7강 : postman
491
작성한 질문수 2

index.js
const bodyParser = require('body-parser');
const {User} = require("./models/User");
//application/x-www-form-urlencoded 정보 분석
app.use(bodyParser.urlencoded({extended: true}))
//application/json파일을 분석
app.use(bodyParser.json())app.get('/',(req, res) => {res.send('Hello Word!')})
app.post('/register',(req,res)=>{
//회원가입할 때 필요한 정보들을 client에서 가져오면,
//그 정보들을 DB에 넣어준다.
const user = new User(req.body);
//user모델에 정보가 저장됨
//실패 시, 실패한 정보를 보내줌
user.save((err, userInfo) => {
if(err) return res.json({success: false, err})
return res.status(200).json({
success: true
})
})
})
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}
TypeError: User is not a constructor
이런 에러가 나옵니다ㅠ.. mongoDB는 연결잘되었구요.
코드는 다 동일하게 작성했는데 왜이럴까요..
답변 1
깃 이메일이랑 비번이 필요하다고 하네요
0
38
1
404 에러
0
105
1
34강 인증 체크에서 element 사용 때문에 에러나시는 분들 이렇게 하심 됩니다.
0
121
1
로그인, 로그아웃, 토근 작동 안 함
0
241
0
9강 오류 어떻게 해결하나요?
0
195
1
localhost 에서 연결을 거부했습니다.
0
1941
4
포스트맨에서 true가 안떠요
0
152
1
왜 안되나요
0
130
1
몽고db 연결 오류가 납니다 위에껀 입력한 코드, 아래껀 터미널이에요
0
244
1
로그아웃 401 에러(Unauthorized)
0
506
2
암호가 해싱되지 않고 입력값 그대로 db에 저장되는 문제
0
151
1
7강중에서
0
167
2
User.findByToken is not a function
0
214
1
루트 디렉토리
0
275
1
useState
0
564
1
프록시 잘 설정했는데도 404 오류 뜨는 분들
5
879
6
webpack 관련 에러 질문
0
221
1
리액트 관련 질문
0
275
1
14강 로그아웃 안됨
0
319
1
mongoDB 데이터 확인하는 법
0
413
1
postman 에러
0
295
1
선생님 리덕스를 사용하면 어떠한 부분이 좋은지 알 수 있을까요?
0
236
1
다음과 같은 에러들이 발생합니다.
0
275
1
14강 로그아웃 기능 구현시 postman에서 Cannot POST 오류가 뜹니다.
0
380
1





