안녕하세요 개발자 정씨입니다.
해당 카테고리에 올라올 게시글들은 특정 목적을 위한 프로젝트가 아니라
그 동안 실무에서 활용한 NodeJS와 ExpressJS의 내용들을 정리할 예정입니다.
1. 프로젝트 생성
# 프로젝트 생성
mkdir main-server
cd main-server
npm init -y
# 필요한 모듈 설치
npm install express
2. app.js
- app.js는 진입점 파일로, NodeJS App을 실행하는 역할을 합니다.
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
3. start
- package.json의 script 부분을 아래와 같이 추가해줍니다.
"scripts": {
"start": "node app.js",
},
- npm start를 명령어창에 치면 매우 익숙한 화면을 볼 수 있습니다.
'ExpressJS' 카테고리의 다른 글
Chapter5 - Session & JWT (0) | 2024.01.28 |
---|---|
Chapter4 - Redis (0) | 2023.11.20 |
Chapter3 - DB연결 (0) | 2023.09.19 |
Chapter2 - 프로젝트 구조 (0) | 2023.09.17 |