TIL&WIL(36)
-
RESTful API [ TIL ]
Problem RESTful 은 무엇인가 Try 클라이언트와 서버가 통신하기 위해 따라야 하는 규칙을 정의한 것이라고 한다. 여기서 REST 는 무엇이고 ful 이 뭐고 정리가 안되어 있는 느낌이라 검색하여 찾아보았다. Solve REST(Representational State Transfer)는 인터넷과 같은 복잡한 네트워크에서 통신을 관리하기 위한 지침으로 만들어 졌다. REST 아키텍처를 구현하는 웹 서비스를 RESTful 이라고 하고 이 용어는 일반적으로 RESTful 웹 API 를 나타낸다고 한다. https://aws.amazon.com/ko/what-is/restful-api/ RESTful API란 무엇인가요? - RESTful API 설명 - AWS Amazon API Gateway..
2023.06.25 -
express [ TIL ] [ node.js ]
Problem express 는 무엇인가 Try npm install express const express = require('express') const app = express() const port = 4001 app.get('/', (req, res) => { res.send('안녕 세상아'); }) app.listen(port, () => { console.log(`http://localhost:${port} 연결완료`) }) Solve - node.js 위에서 동작하는 웹 프레임워크 - node.js 개발 시 개발을 빠르고 손쉽게 도와주는 역할, 이는 미들웨어 구조 때문에 가능한 것이다. 자바스크립트 코드로 작성된 다양한 기능의 미들웨어는 개발자가 필요한 것만 선택하여 express 와 ..
2023.06.25 -
params [ TIL ] [ node.js ]
Problem req.params 가 빈 객체가 전달된다. // index.js const express = require("express"); const commentRouter = require("./comments"); const postRouter = require("./posts"); const router = express.Router(); router.use("/posts", postRouter); router.use("/posts/:_postId", commentRouter) module.exports = router; // comments.js router.post("/comments", async (req, res) => { try { const postId = req.params; ..
2023.06.24 -
async / await [ TIL ] [ node.js ]
Problem express 를 이용하여 간단한 게시판 api 를 만들던중 undefined 가 발생했다. Try router.post("/", async (req, res) => { console.log(req.body); try { const { title, content, userId } = postCreateValidation.validateAsync( req.body ); console.log(title, content, userId); const post = await Post.create({ title, content, userId, }); res.json(post); } catch (err) { if (err.isJoi) { return res.status(422).json({ messa..
2023.06.22 -
태스크 큐 이벤트루프(3) [ TIL ] [ Javascript ]
Problem 태스크 큐에 대해서 알아보장 Try 태스크 큐는 두가지 종류라고 한다. 첫번째는 마이크로 태스크 큐, 두번째는 태스크 큐 이렇게 두개의 태스크 큐가 존재한다. 마이크로 태스크는 자신을 생성한 함수 또는 프로그램이 종료됐고 JavaScript 실행 스택이 빈 후에, 그러나 사용자 에이전트가 스크립트 실행 환경을 운용하기 위해 사용하는 이벤트 루프로 통제권을 넘기기 전에 실행되는 짧은 함수입니다. - mdn web docs - 코드 실행 console.log("안녕하셈!"); setTimeout(() => { console.log("약 2초가 지났습니다."); }, 2000); setTimeout(() => { console.log("약 0초가 지났습니다."); }, 0); console.l..
2023.06.21 -
Web API 이벤트루프(2) [ TIL ] [ Javascript ]
Problem Web API 에 대해서 알아보장 Try Web API 는 브라우저에서 제공하는 API 로 DOM, Ajax, TimeOut 등이 있다. CallStack 에서 실행된 비동기 함수는 Web API 를 호출하고, Web API 는 콜백 함수를 테스크 큐에 넣는다. 코드 작성 console.time("첫번째 setTimeout"); console.time("두번째 setTimeout"); setTimeout(function timer() { console.log("2초가 걸릴까요?"); console.timeEnd("첫번째 setTimeout"); }, 2000); console.log("안녕하심니까"); setTimeout(function timeout() { console.log("5초가..
2023.06.20