users.js 770 Bytes
Newer Older
Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
1
2
3
4
5
var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  console.log('/users post req.body', req.body)
  User.findOne({ id: req.body.id }, function (err, users) {
    if (err) return res.status(500).json({ error: err });

    if (users) {
      return res.status(404).json({ error: '이미 존재하는 아이디입니다.' })
    };

    const user = new User({
      name: req.body.name,
      id: req.body.id,
      password: req.body.password,
    });

    user.save()
      .then((result) => {
        console.log(result);
        res.status(201).json(result);
      })
      .catch((err) => {
        console.error(err);
        next(err);
      });
  })
Kim, Chaerin's avatar
어헛    
Kim, Chaerin committed
30
31
32
});

module.exports = router;