- Today
- Total
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- JavaScript
- findByIdAndDelete
- certbot
- jsonwebtoken
- moment
- async
- Find
- css
- single quote
- sequelize
- RDS
- double quote
- Express
- flutter
- clipBehavior
- https
- TypeScript
- mongodb
- await
- atlas
- nginx
- AWS
- TailwindCSS
- wil
- Node.js
- til
- EC2
- Nodejs
- MYSQL
- mongoose
목록전체 글 (94)
기억 휘발 방지소
includes()는 배열이 특정 요소를 포함하고 있는지를 판별하는 메소드이다. const numbers = [1, 2, 3, 4, 5]; console.log(numbers.includes(5)); // true console.log(numbers.includes(6)); // false const names = ["Kim", "Park", "Lee"]; console.log(names.includes("Kim")); // true console.log(names.includes("AAA")); // false 배열에 특정 요소가 포함되어 있다면 true를 반환하고 그렇지 않으면 false를 반환한다. 문자열에서도 쓸 수 있다! const greeting = "Hello JavaScript"; cons..
find() 메서드는 주어진 판별 함수를 만족하는 첫 번째 요소의 값을 반환한다. 그런 요소가 없다면 undefined를 반환한다. (출처: MDN) const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const found = array.find((el) => el > 5); console.log(found); // 6 객체들이 들어있는 배열에서도 다음과 같이 쓸 수 있다. const array = [ { name: "Kim", age: 23, hobby: "eat" }, { name: "Park", age: 32, hobby: "drive" }, ]; const found = array.find((el) => el.name === "Kim"); console.log(fo..
아래 명령어로 express-session을 설치할 수 있다. npm i express-session import express from "express"; import session from "express-session"; const app = express(); app.use( session({ httpOnly: true, secure: true, secret: "I am secret key", resave: false, saveUninitialized: false, cookie: { httpOnly: true, secure: true, maxAge: 20000, } }) ); httpOnly: 자바스크립트를 통해 세션 쿠키를 사용할 수 없도록 함 secure: https 환경에서만 session ..
📌 해시함수란? 해시함수(Hash Function)은 임의의 길이의 데이터를 고정된 길이의 데이터를 매핑하는 함수이다. 출처: 위키백과 해시함수는 단방향 암호화라고도 한다. 단방향 암호화란 A가 해시함수를 거쳐 B가 나왔다고 했을 때 B를 가지고 다시 A를 알아낼 수 없다! (반대의 개념으로 양방향 암호화가 있는데 양방향 암호화는 A를 B로 암호화하고 B를 다시 복호화하여 A를 알아낼 수 있다.) 또한 어떤 입력에 대해서 항상 같은 결과가 나온다. 보통 회원가입을 할 때 비밀번호를 DB에 저장할 때 해시함수를 거친 결과값을 DB에 저장한다. 그렇게 하면 DB를 누군가 해킹했을 때 해시함수를 갖고 비밀번호를 역으로 알아낼 수 없다!! 📌 bcrypt bcrypt는 해시함수 중 하나이다. 자바스크립트 뿐만 ..
findByIdAndDelete()에 매개변수로는 id값이 들어온다. 몽고DB에 _id값 findOneAndDelete({ _id: id })를 줄인 버전이라고 할 수 있다. export const deletePost = async (req, res) => { const { id } = req.params; await Post.findByIdAndDelete(id); return res.redirect("/"); };
📌 findByIdAndUpdate를 쓰지 않고 수정하기 title과 description을 수정할거다. findById()로 DB에서 문서들을 가져오고 post.title = title; post.description = description; 으로 수정하려고하는 값들을 바꿔주고 post.save()를 해준다. export const postEdit = async (req, res) => { const { id } = req.params; const { title, description } = req.body; const post = await Post.findById(id); // 수정 post.title = title; post.description = description; await post.s..