[Node.js] 서버 시작하기

Gomao·2023년 4월 16일
0

Node.js

목록 보기
8/8

1. 터미널 열기

terminal

npm init

2. express 라이브러리 설치

terminal

npm install express

3. 서버 띄우기

const express = require("express")
const app = express();
app.listen(8080, () => {
	console.log("listening on 8080")
}

4. 서버 작동하기

terminal

node index.js

5. 변경사항 자동 적용하기

terminal

npm install -g nodemon

이후 아래와 같이 파일을 실행해주면 된다.

nodemon index.js

6. 서버 접속하기

이제 app.listen을 통해 접속한 주소로
서버와 통신을 할 수 있다.
app.listen(8080)으로 정의하였으므로,
브라우저에서 localhost:8080으로 접근 가능하다

profile
코딩꿈나무 고마오

0개의 댓글