index.js
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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