응답 값이 이렇게 나오는데 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}!`));
다 정상인데 conlose.log(userInfo) 해보면 ponstman 에서 send 했을때 콘솔에 undefined 라고 나옵니다. 값이 들어오지 않아서 그런거 같은데... user와 req.body에도 다 있는 값이 왜 userInfo에는 없는걸까요...