정승호

post 기능 추가

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
......@@ -12,7 +19,22 @@ mongoose.connect('mongodb+srv://platoon07:wony9795!!@2020oss-ysxss.mongodb.net/t
app.get('/', (req,res) => res.send('Hello world!!'))
app.listen(port, () => console.log('example app listen on port ${port} !'))
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
\ No newline at end of file
......
......@@ -14,6 +14,7 @@
"author": "seungho",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongoose": "^5.9.15"
}
......