1.npm init
Node.js 프로젝트를 초기화하고 package.json 파일을 생성합니다.
npm init -y 를하면 기본값으로 자동설정합니다.
2.npm install express
npm을 통해 express를 설치해준다.
3.index.js
작동을확인하기 위한 index.js 파일을 작성해본다.
// express 모듈 가져오기
const express = require('express');
const app = express();
// 포트 설정
const port = 3000;
// 기본 라우트 설정
app.get('/', (req, res) => {
res.send('Hello, World!');
});
// 서버 시작
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
4. node index.js
index.js를 실행후 http://localhost:3000로 접속해본다.
> node index.js
> express@1.0.0 start
> node index.js
Server is running on http://localhost:3000
반응형
'BackEnd > Express.js' 카테고리의 다른 글
[Express.js] 홈페이지 처리 (0) | 2024.09.03 |
---|---|
[Express.js] app.get() (1) | 2024.09.03 |
[Express.js] Express.js란? (0) | 2024.09.02 |