-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 1.05 KB
/
index.js
File metadata and controls
36 lines (28 loc) · 1.05 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
const express = require('express')
const app = express()
const port = 4000
const { User } = require("./models/User")
const config = require('./config/key')
//application/x-www-form-urlencoded
app.use(express.urlencoded({exteded: true}));
//application/json
app.use(express.json())
const mongoose = require('mongoose')
mongoose.connect( config.mongoURI, {
useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false
}).then(() => console.log('MongoDB Connected...'))
.catch(err => console.log(err))
app.get('/', (req, res) => res.send('hello world! This is my place!'))
app.post('/register', (req, res) => {
//회원가입시 필요한 정보들을 client에서 가져오고 MongoDB에 넣어준다.
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
})
})
})
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))