NodeJs express

Node.Js를 알게 된지 반년이 넘어가는데 이제야 깃 블로그를 시작한 본인이 너무 바보 같지만 지금까지 공부한 것들을 블로그를 통해 기록하려한다.. 너무 많은게 문제지만 하나하나
정리해 나가야 겠다.

NodeJs express 시작하기

npm init 명령어 실행 후 터미널에서 express 패키지를 install 한다.

1
npm install express\

그리고 app.js에 다음과 같이 코드를 작성해준다.

1
2
3
4
5
6
7
8
9
10
11
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 at http://localhost:${port}`)
})

작성을 하고 터미널에서 node app.js 명령어를 통해 app..js파일을 실행한다.


브라우저를 통해 localhost:3000 포트로 접속 하니 Hello world 라는 문구가 보인다. 이렇게 간단하게 서버를 하나 열 수 있게 되었다.

Author

han Ju Ryeon

Posted on

2021-09-09

Updated on

2021-12-05

Licensed under

댓글