Search
☑️

241021_1634_nodeJS PM2 세팅하기

Node.js 애플리케이션을 pm2로 관리하는 기본적인 예시는 아래와 같다.

1. pm2 설치

npm install pm2 -g
Shell
복사

2. Node.js 애플리케이션 생성

// app.js const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, world!\n'); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); });
JavaScript
복사

3. pm2로 애플리케이션 실행

pm2 start app.j
Shell
복사

4. pm2 상태 확인

pm2 list
Shell
복사

5. 애플리케이션 재시작

pm2 restart app.js
Shell
복사

6. 애플리케이션 종료

pm2 stop app.js
Shell
복사

7. 애플리케이션 삭제

pm2 delete app.js
Shell
복사

8. pm2 로그 확인

pm2 logs
Shell
복사

9. pm2 설정 저장 (서버 재부팅 후에도 자동 실행)

pm2 save
Shell
복사

10. pm2 시스템 서비스 등록

pm2 startup
Shell
복사
위 예시를 통해 pm2를 사용하여 Node.js 애플리케이션을 관리하고 모니터링할 수 있음.

안녕하세요

한국전자기술연구원 김영광입니다.
관련 기술 문의와 R&D 공동 연구 사업 관련 문의는 “glory@keti.re.kr”로 연락 부탁드립니다.

Hello

I'm Yeonggwang Kim from the Korea Electronics Research Institute.
For technical and business inquiries, please contact me at “glory@keti.re.kr”