728x90
ReferenceError: bodyParser is not defined
at Object.<anonymous> (C:\study_nodejs_react\01_node_react_basic\index.js:8:9)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mystudy@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mystudy@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\kwg94\AppData\Roaming\npm-cache\_logs\2022-01-30T11_23_29_270Z-debug.log
바디파서를 사용하기위해서 npm i --save body-parser 를 이용하여 바디파서를 다운받았다.
npm i body-parser --save
그런데... 저런 에러가 발생한것...
설치는 분명 잘 된것같다.
const express = require('express');
const app = express();
const port = 3000;
const { User } = require('./model/User');
// application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: true}));
// application/json
app.use(bodyParser.json());
const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://cine:cine@cluster0.7sr4t.mongodb.net/myFirstDatabase')
.then(() => console.log('MongoDB Connected...'))
.catch(arr => console.log(arr))
app.get('/', (req, res) => {
res.send('Hello, Express!');
})
app.post('/register', (req, res) => {
// 회원가입에 필요한 정보들을 클라이언트에서 가져오면 그것들을 데이터베이스에 넣어준다.
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 on port ${port}!`)
});
대체 무슨 문제가 있단말인가하고보니
const bodyParser = require('body-parser');
모듈을 안가져왔다.
그러니까 당연히 못찾기 멍충아..
이렇게 오늘도 멍청했다
728x90