index.js 1.19 KB

const express = require('express')
const app = express()
const bodyParser = require('body-parser');
const port = 5000

const { User } = require('./models/Users');

app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());


const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://platoon07:wony9795!!@2020oss-ysxss.mongodb.net/test?retryWrites=true&w=majority',{
    useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex : true, useFindAndModify: false
}).then(() => console.log('MongoDb connected....'))
  .catch(err => console.log('Error'))



app.get('/', (req,res) => res.send('Hello world!!'))

app.post('/register', (req, res) => {
    // 회원 가입시 필요한 정보들을 client에서 가져오면
    // 그것들을 데이터베이스에 넣어준다. 
    const user = new User(req.body)

    user.save((err, userInfo) => {
        if(err) return res.json({success : false, err})
        return res.status(200).json({
            success : true
        })
    }) // MongoDb에 저징
})


app.listen(port, () => console.log('example app listen on port ${port}!'))


// mongodb+srv://platoon07:<password>@2020oss-ysxss.mongodb.net/test?retryWrites=true&w=majority