wetube 7.0 ~ 7.4

이주왕·2022년 3월 14일
0

Node Js

목록 보기
9/10

Unique

User.js에서 userSchema를 만들 때 unique:true 로 설정을 하게 되면 똑같은 값을 db에 생성할 수 없다. (ex/ username, email)

Bcrypt

bcrypt를 통해 password를 hashing 할 수 있다. User.js에서 "pre" middleware를 사용해서 password를 hashing 한다.

userSchema.pre("save", async function() {
	this.password = await bcrypt.hash(this.password, 5)
    })

5가 의미하는 것은 password를 몇 번 hashing 할 것인지 정하는 것이다.

$or

or operator를 통해서 2개 이상의 db 안의 값을 비교할 수 있다.

const exists = User.exists({$or: [{username}], [{email}] })

Status Code

res.status(400).render({})

.status() 를 통해 원하는 status code를 브라우저에 보낼 수 있다.

profile
Learn more

0개의 댓글

Powered by GraphCDN, the GraphQL CDN