Express란

G-NOTE·2021년 5월 17일
0

server/db

목록 보기
2/4

개념

Express는 Node.js 환경에서 동작하는 웹 애플리케이션 프레임워크로 클라이언트 사이드가 아닌 서버 사이드 프레임워크

왜 Express를 사용할까?

  • 웹 서버 구축을 보다 쉽게 할 수 있도록 도와준다.
  • 가볍고 빠르다.
  • 현재 Node.js 프레임워크 중 가장 널리 쓰이고 있다.

사용 방법

$ npm install express --save
  • --save 옵션으로 설치된 Node 모듈은 package.json 파일 내의 dependencies 목록에 추가되고, 이후 app 디렉토리에서 npm install을 실행하면 종속 항목 목록 내의 모듈이 자동으로 설치된다.
const express = require('express');
const app = express();

const myLogger = function (req, res, next) {
  console.log('LOGGED'); 
  // 이 부분을 req, res 객체를 이용해 고치면, 모든 요청에 대한 로그를 찍을 수 있습니다.
  next();
};

app.use(myLogger);

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.listen(3000);

참조

https://expressjs.com/ko/starter/installing.html
https://velopert.com/294

profile
FE Developer

0개의 댓글