노드 자동실행 및 백그라운드 실행할 때 사용함
1. 환경변수 설정
- 윗칸 사용자 변수에 값 새로 만들기
- 변수 : PM2_HOME, 값 C:\etc\.pm2
2. pm2 설치
npm i -g pm2 pm2-windows-service npm-check-updates
-g = 글로벌하게 어디서든 쓸 수 있게 하는 설정
3. 그런 다음 윈도우즈 서비스에 등록
pm2-service-install
아래와 같이 설정
> Perform environment setup (recommended)? Yes
> Set PM2_HOME? Yes PM2_HOME value (this path should be accessible to the service user and should not contain any "user-context" variables [e.g. %APPDATA%]): c:\etc\.pm2\ -이거만 설정하고 다 YES에 엔터 눌러도된다.
> Set PM2_SERVICE_SCRIPTS (the list of start-up scripts for pm2)? Yes
> Set the list of start scripts/files (semi-colon separated json config files or js files) (I left this one blank)
> Set PM2_SERVICE_PM2_DIR (the location of the global pm2 to use with the service)? [recommended] Yes Specify the directory containing the pm2 version to be used by the service C:\USERS\ADMINISTRATOR\APPDATA\ROAMING\NPM\node_modules\pm2\index.js PM2 service installed and started.
4. pm2 시작
pm2 start <파일명> --watch 로 파일을 pm2에 추가
- --watch는 실시간으로 업데이트가 적용되게 해주는 옵션
5. pm2 저장
pm2 save로 현제 상태를 저장한다.
6. pm2를 서비스에서 자동 재시작으로 설정해준다
그리고 컴퓨터 재 시작 후에 잘 실행되는지 확인
'일반' 카테고리의 다른 글
Moment.js (0) | 2023.06.02 |
---|---|
일정한 시간 마다 실행 (0) | 2023.05.10 |
20230427 TODO (0) | 2023.04.27 |
JavaScript - Promise.all () (0) | 2023.04.27 |
Nodejs -> mysql 대량의 값을 insert 또는 delete (0) | 2023.04.25 |