본문 바로가기
Study/Node.js

[Node] PM2 설치

by M개발자 2021. 8. 31.
반응형

1. PM2 설치

npm install pm2 -g

2. PM2 설치 확인

 pm2 -version

** local - 보안 오류 발생 **

pm2 : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Users\___\AppData\Roaming\npm\pm2.ps1 파일을 로드할 수 없습니다. 자세한 내용은 about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170)를 참조하십시오.
위치 줄:1 문자:1
+ pm2 -version
+ ~~~
    + CategoryInfo          : 보안 오류: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

 

PowerShell을 관리자권한으로 실행한다.

Set-ExecutionPolicy RemoteSigned

다시 버전 확인을 해보면 잘 돌아가는걸 볼 수 있다다닷

 

3. PM2 실행

pm2 start app.js //js 파일 이름

실행하면 귀여운 PM2를 볼 수 있다~~

4. pm2 kill

pm2 종료

PS D:\nodejs> pm2 kill
[PM2] Applying action deleteProcessId on app [all](ids: [ 0 ])
[PM2] [index](0) ✓
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped

5. pm2 --watch

파일 변경 사항을 감시해 시작한다 

PS D:> pm2 start app.js --watch
[PM2] Starting D:\app.js in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ app                │ fork     │ 0    │ online    │ 0%       │ 29.3mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

6. pm2 restart 

실행을 다시하게 될 경우 kill 후 start를 하는 것보다 재시작을 하는 게 낫다. 

pm2 restart app.js //js 파일 이름

 

-- 그 외는 잘 정리해두신 블로거님 참고!!

https://hellominchan.tistory.com/11

 


 

참고 자료

PM2 설치 : https://dydals5678.tistory.com/100

보안 오류 해결 : https://www.hahwul.com/2017/08/23/powershell-execution-of-scripts-is/

 

반응형

댓글