씨네
공부하는 개발자 강씨네
씨네
  • 분류 전체보기 (460)
    • Web (21)
      • HTML (11)
      • CSS (10)
    • JS 관련 (49)
      • JavaScript (27)
      • JQuery (22)
    • TS 관련 (15)
      • TypeScript (15)
    • NodeJS (7)
      • NodeJS (7)
    • 따라하며 배우는 시리즈 (23)
      • NodeJS & ReactJS Basic (23)
      • NodeJS & ReactJS Movie (0)
      • NodeJS & ReactJS Youtube (0)
      • NodeJS & ReactJS ChatBot (0)
    • SPA (14)
      • React (14)
      • Vue (0)
      • Anguler (0)
    • Java 관련 (118)
      • Java (52)
      • JDBC (6)
      • JSP & Servlet (18)
      • Spring Legecy (38)
      • SpringBoot (4)
    • Python (26)
      • Python (20)
      • PyMongo (1)
      • Django (5)
    • Git (24)
      • Github (24)
    • RDB (22)
      • Oracle (21)
      • MySQL (1)
    • NoSQL (5)
      • MongoDB (5)
    • OS (4)
      • Linux (4)
    • 빅데이터 (2)
      • hadoop (2)
    • IDE (20)
      • eclipse (11)
      • VSCODE (4)
      • VisualStudio (1)
      • IntelliJ (1)
      • PyCharm (1)
      • DBeaver (2)
    • Install (3)
      • Tomcat (1)
      • Docker (1)
      • Anaconda (1)
    • 오류&에러 (28)
      • TS (2)
      • NodeJS (7)
      • SQL (8)
      • Java (1)
      • Spring (4)
      • Git (6)
      • 기타 (0)
    • 알고리즘 (67)
      • 수열 (1)
      • 백준(backjoon) (39)
      • Programmers (27)
    • 자격증 (5)
      • SQLD (5)
    • 기타 (2)
    • IT유튜브로 지식쌓기 (2)

공지사항

인기 글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
씨네

공부하는 개발자 강씨네

ReferenceError: bodyParser is not defined
오류&에러/NodeJS

ReferenceError: bodyParser is not defined

2022. 8. 30. 14:28
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
저작자표시 (새창열림)

'오류&에러 > NodeJS' 카테고리의 다른 글

NodeJS로 express와 mongoDB 연결시 오류 해결 Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is o..  (0) 2023.01.31
[NodeJS] npm ERR! code ENOENT npm ERR! syscall rename  (10) 2022.09.24
MongoInvalidArgumentError: No AuthProvider for DEFAULT defined.  (0) 2022.08.28
MongoParseError: options usecreateindex, usefindanmodify are not supported  (0) 2022.08.27
Error: Cannot find module 'webpack-cli/bin/config-yargs'  (0) 2021.06.24
    '오류&에러/NodeJS' 카테고리의 다른 글
    • NodeJS로 express와 mongoDB 연결시 오류 해결 Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is o..
    • [NodeJS] npm ERR! code ENOENT npm ERR! syscall rename
    • MongoInvalidArgumentError: No AuthProvider for DEFAULT defined.
    • MongoParseError: options usecreateindex, usefindanmodify are not supported
    씨네
    씨네
    개발자 씨네가 공부하는 내용을 기록 겸 공유하는 블로그입니다!

    티스토리툴바