inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

post 전송 에러 질문드립니다

373

이범진

작성한 질문수 3

0

index.js
const express = require("express"); //express import
const app = express();
const port = 5006;
const bodyParser = require("body-parser");
const { User } = require("./models/User");
//applicatioin /x-www-form -url encoded

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

const mongoose = require("mongoose");
mongoose
  .connect(
    "mongodb+srv://euan:abcd1234@boilerplate.tywi2.mongodb.net/?retryWrites=true&w=majority",
    {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useCreateIndex: true,
      useFindAndModify: false,
    }
  )
  .then(() => console.log("mongo db is connected.."))
  .catch((err) => console.log(err));

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

app.post("/register", (req, res) => {
  const user = new User(req.body);

  user.save((err, userInfo) => {
    if (errreturn res.json({ success: false, err });
    return res.status(200).json({
      success: ture,
    });
  });
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});
user.js
const mongoose = require("mongoose");

const userSchema = mongoose.Schema({
  name: {
    type: String,
    maxlength: 500,
  },

  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 };
------------------------------------------------------------------
{
    "success"false,
    "err": {
        "driver"true,
        "name""MongoError",
        "index"0,
        "code"11000,
        "keyPattern": {
            "email"1
        },
        "keyValue": {
            "email""maplestory1419@gmail.com"
        }
    }
}
서버확인하였는데 이런식으로 에러가 나옵니다. name에 에러가 있는것 가은데 혼자힘으로 해결이 힘들어 질문드립니다!
감사합니다!
몽고db연결도 확인하였습니다.
자꾸 질문드려서 죄송하네요 ㅠㅠ console 창에도 에러가 없으니 뭐가문제인지 단서를 찾을수가 없습니다 ㅠㅠ
ps강의 정말감사합니다 ㅠ커피라도 대접해드리고싶네용

nodejs react

답변 3

1

최율겸

혹시라도 이런 오류가 뜨는분들 보시라고 답글 달아놓을게요

email 속성에 unique가 있어서 뜨는것으로 확인됩니다

회원가입이 되어있는데 또 똑같은 이메일로 회원가입을 해서 뜨는 오류메시지 입니다

0

이범진

회원가입입니다!

postman 에서 send시 발생합니다(이번강의 보고 카피한 것입니다)

0

John Ahn

안녕하세요 

현재 이 상황이 어떤 요청을 할때 나오는 것인가요 ?  회원 가입 할때 인가요 ?  아니면 로그인 할 때 인가요 ~ ? 

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

0

34

1

404 에러

0

101

1

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

0

118

1

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

0

237

0

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

0

193

1

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

0

1924

4

포스트맨에서 true가 안떠요

0

150

1

왜 안되나요

0

128

1

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

0

243

1

로그아웃 401 에러(Unauthorized)

0

503

2

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

0

148

1

7강중에서

0

162

2

User.findByToken is not a function

0

210

1

루트 디렉토리

0

268

1

useState

0

560

1

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

5

874

6

webpack 관련 에러 질문

0

218

1

리액트 관련 질문

0

271

1

14강 로그아웃 안됨

0

318

1

mongoDB 데이터 확인하는 법

0

407

1

postman 에러

0

290

1

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

0

232

1

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

0

272

1

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

0

379

1