Suzie's Blog

[Express] Express Server 구축하는 방법 | 서버가 켜져있는지 확인하는 방법 본문

개발

[Express] Express Server 구축하는 방법 | 서버가 켜져있는지 확인하는 방법

Iuna 2023. 9. 1. 17:02
반응형
SMALL

Express server 구축하는 방법

 

1. 디렉토리를 생성한다

mkdir directoryName

2. index.js 파일을 만든다

3. npm init 을 실행한다 (-y : yes for every single questions)

npm init -y

4. Express 패키지를 설치한다

npm i Express

5. Server Application을 index.js에 작성해준다

import express from "express";
const app = express();
const port = 1000;

app.listen(port, () => {
  console.log(`Server running on port ${port}.`);
});

6. 서버를 켜준다

node index.js

 

서버가 켜져 있는지 확인하는 방법

1. localhost:1000 으로 접속해서 확인 (Cannot GET \ 이 보이면 연결된것) 

2. 터미널에 아래와 같이 입력하면 현재 켜져있는 모든 서버 확인 가능

- Windows : netstat -ano | findstr "LISTENING"

- MAC/Linux : sudo lsof -i -P -n | grep LISTEN 

반응형
LIST