-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
코딩 스타일에 대해 질문 있습니다.
18.10.09 19:38 작성 조회수 95
0
github의 models 안에 들어있는 코드들을 보면 아래와 같구요,
a) module.exports = (sequelize, DataTypes) => ( -사이에 기타 코드들-)
강좌중의 코드를 따라가 보면 아래와 같습니다.
b) module.exports =((sequelize, DataTypes) =>{ -기타 코드들- })
- b)의 형식으로 했을 때는 아래와 같은 에러 코드를 받았습니다. 아무래도 오타 때문이겠죠?
둘의 차이가 뭔가요?
module.exports = variableName 과 같은 식으로 exports 하지 않은 특별한 이유가 있나요?
C:UsersinomoDesktopnode js 교과서snsmodelsindex.js:16
db.User.hasMany(db.Post);
^
TypeError: Cannot read property 'hasMany' of undefined
이하는 에러를 받았을 때의 user.js의 코드 전문입니다.
module.exports =((sequelize, DataTypes) =>{ sequelize.define('user', {
email: {
type: DataTypes.STRING(40),
allowNull:false,
unique:true,
},
nick: {
type: DataTypes.STRING(15),
allowNull: false,
},
password:{
type: DataTypes.STRING(100),
allowNull: true,
},
provider: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: 'local',
},
snsId: {
type: DataTypes.STRING(10),
allowNull: true,
}
}, {
timestamps: true,
paranoid: true,
})
})
답변을 작성해보세요.
0
0
조현영
지식공유자2018.10.10
() => (값)
은
() => { return 값 }
과 같습니다.
따라서 return sequelize.define를 하는 게 목적이므로
() => (
sequelize.define()
)
을 해야 됩니다.
module.exports = variableName는 그냥 (sequelize.define()부분을 변수로 뺀 것일 뿐 더이상 특별한 의미가 없습니다.
답변 2