본문 바로가기

Node.Js

[Node.js] Express 사용하여 서버 실행

반응형

npm install express 입력 하여 설치

 

설치 하면 node_modules 라는 폴더 생성됨

package.json 에서 dependencies 에 보면 express 가 명시됨

 

app.js 에서

const express = require('express');

입력

 

require -> node_modules 안에서

('express') -> express 라는 것을 사용하겠다

const express = require('express');
const app = express();

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

//3000번 포트를 사용 할 것이다
app.listen(3000, function (req, res) {
    console.log("port 3000 서버가 실행 되고 있음")
})

입력 후, 터미널에 node app.js 하여 실행

 

크롬에 localhost:3000 으로 진입 하면 서버실행 되고 있는것을 확인 할 수 있다

반응형

'Node.Js' 카테고리의 다른 글

[Node.js] mainRouter.js  (0) 2023.01.14
[Node.js] 보안 관련 helmet 설치  (0) 2023.01.14
[Node.js] mac에서 supervisor 설치 시, command not found 에러  (0) 2023.01.14
[Node.js] 폴더 생성과 구조  (0) 2023.01.13
[Node.Js] 1강 HTTP  (0) 2021.02.24