inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

따라하며 배우는 노드, 리액트 시리즈 - 기본 강의

노드 리액트 기초 강의 #7 BodyParser & PostMan & 회원 가입 기능

postman 오류입니다 도와주세요 ㅠㅠ

675

도행우

작성한 질문수 1

0

응답 값이 이렇게 나오는데 err 메세지에 아무것도 적혀있지 않아서 모르겠습니다 알려주세요 ㅠㅠ

 

다음은 제 코드입니다

User.js

const mongoose = require("mongoose");

const userSchema = mongoose.Schema({
  name: {
    type: String,
    maxlength: 50,
  },
  email: {
    type: String,
    trim: true,
    unique: 1,
  },
  password: {
    type: String,
    minlength: 5,
  },
  lastname: {
    type: String,
    maxlength: 50,
  },
  role: {
    type: Number,
    default: 0,
  },
  image: String,
  token: {
    type: String,
  },
  tokenExp: {
    type: Number,
  },
});

const User = mongoose.model("User", userSchema);

module.exports = { User };

index.js

const express = require("express"); //express module 호출
const app = express();
const port = 5000;
const { User } = require("./models/User");
//application/x-www/form-urlencoded
app.use(express.urlencoded({ extended: true })); //express 4.x 버전부터는 express에 bodyParser가 내장됩니다.

//application/json
app.use(express.json());

const mongoose = require("mongoose");
mongoose
  .connect(
    "mongodb+srv://do:1234@cluster0.e91ss.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
  )
  .then(() => console.log("MongoDB Connected..."))
  .catch((e) => console.log("MongoDB error: ", e));

app.get("/", (req, res) => res.send("Hello World!"));

app.post("/register", (req, res) => {
  //회원 가입 할때 필요한 정보들을 client에서 가져오면
  //그것들을 데이터 베이스에 넣어준다.

  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}!`));

nodejs react

답변 1

0

John Ahn

안녕하세요!! 

 

몇 가지 생각되는 게 있는데 

1. 디비가 잘 연결되어있는지 

 

2. req.body에 전달해준 값들이 잘 들어있는지 

 

3. userInfo에 어떠한 값이 있는지도 확인해봐 주세요! 

만약 이렇게 해도 해결이 안 되면 전체 소스코드랑 같이 올려주시면 직접 봐보겠습니다 

 

감사합니다.

0

Sung Jae Lee

다 정상인데 conlose.log(userInfo) 해보면 ponstman 에서 send 했을때 콘솔에 undefined 라고 나옵니다. 값이 들어오지 않아서 그런거 같은데... user와 req.body에도 다 있는 값이 왜 userInfo에는 없는걸까요...

깃 이메일이랑 비번이 필요하다고 하네요

0

54

1

404 에러

0

120

1

34강 인증 체크에서 element 사용 때문에 에러나시는 분들 이렇게 하심 됩니다.

0

138

1

로그인, 로그아웃, 토근 작동 안 함

0

256

0

9강 오류 어떻게 해결하나요?

0

198

1

localhost 에서 연결을 거부했습니다.

0

1972

4

포스트맨에서 true가 안떠요

0

157

1

왜 안되나요

0

133

1

몽고db 연결 오류가 납니다 위에껀 입력한 코드, 아래껀 터미널이에요

0

250

1

로그아웃 401 에러(Unauthorized)

0

519

2

암호가 해싱되지 않고 입력값 그대로 db에 저장되는 문제

0

158

1

7강중에서

0

177

2

User.findByToken is not a function

0

215

1

루트 디렉토리

0

281

1

useState

0

570

1

프록시 잘 설정했는데도 404 오류 뜨는 분들

5

905

6

webpack 관련 에러 질문

0

225

1

리액트 관련 질문

0

282

1

14강 로그아웃 안됨

0

325

1

mongoDB 데이터 확인하는 법

0

414

1

postman 에러

0

297

1

선생님 리덕스를 사용하면 어떠한 부분이 좋은지 알 수 있을까요?

0

240

1

다음과 같은 에러들이 발생합니다.

0

282

1

14강 로그아웃 기능 구현시 postman에서 Cannot POST 오류가 뜹니다.

0

385

1