-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
postman 오류입니다 도와주세요 ㅠㅠ
22.02.07 23:32 작성 조회수 525
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}!`));
답변을 작성해보세요.
0
John Ahn
지식공유자2022.02.10
안녕하세요!!
몇 가지 생각되는 게 있는데
1. 디비가 잘 연결되어있는지
2. req.body에 전달해준 값들이 잘 들어있는지
3. userInfo에 어떠한 값이 있는지도 확인해봐 주세요!
만약 이렇게 해도 해결이 안 되면 전체 소스코드랑 같이 올려주시면 직접 봐보겠습니다
감사합니다.
Sung Jae Lee
2022.04.05
다 정상인데 conlose.log(userInfo) 해보면 ponstman 에서 send 했을때 콘솔에 undefined 라고 나옵니다. 값이 들어오지 않아서 그런거 같은데... user와 req.body에도 다 있는 값이 왜 userInfo에는 없는걸까요...
답변 1