[Node.js] express와 미들웨어


[Node.js] express와 미들웨어

1. 미들웨어란? 미들웨어는 요청과 응답 사이의 중간단계 역할을 하는 존재로, 인증 수행, 예외 처리, 세션처리, 라우터 등 많은 종류가 있습니다. express 는 자체 미들 웨어를 사용해도 되고 다른 사람이 만들어 놓은 미들웨어를 npm 을 통해 설치하여 사용해도 됩니다. 아래 코드는 미들 웨어를 함수로 만들어서 사용한 코드입니다. 서버를 실행하면 localhost:8080/ 에 접속하는 요청이 올때마다 콘솔에 "LOGGED"가 출력됩니다. // app.js const express = require("express"); const app = express(); const myLogger = function (req, res, next) { console.log("LOGGED"); next(); }; app.use(myLogger); app.get("/", function (req, res, next) { res.send("Hello World!"); next(); }); app...


#express #nodejs #미들웨어 #백엔드

원문링크 : [Node.js] express와 미들웨어