uid๋ฅผ ์ธ์ํ์ง ๋ชปํ๋ ๋ฌธ์ ๋ฐ์
req.body๋ body-parser๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ ๋ํดํธ ๊ฐ์ผ๋ก undefined๊ฐ ์ค์ ๋์ด ์๊ธฐ ๋๋ฌธ
body์ json์ ํ์ฑํด์ฃผ๋ 'body-parser'๋ฅผ install ์์ผ์ค
$ npm install body-parser
const bodyParser = require('body-parser');
router.use(
bodyParser.urlencoded({
extended: false,
})
);
router.use(bodyParser.json());
router.post('/info', async (req, res, next) => {
let userId = req.body.uid;
let userEmail = req.body.email;
User.create({
uid: userId,
email: userEmail,
})
.then((result) => {
console.log(result);
res.status(200).json(result);
})
.catch((err) => {
console.log(req.body)
console.error(err);
next(err);
})
})
๋ง ํ์ดํ