Utils/Program

nssm을 사용하여 node.js를 windows 서비스로 만들기(+ log)

jinmc 2021. 11. 8. 16:17
반응형

node.js서버를 만들어서 windows server에 사용하였는데,

재부팅 할 때마다 새로 CLI를 열어서 node server.js를 해줘야 하는 불편함이 있었습니다.

이를 해결하기 위해서 찾은게 nssm입니다.

 

nssm을 이용해서 node.js를 서비스로 만드는 법은, 의외로 간단합니다.

nssm.exe file을 다운받은 후, command line에서 다음과 같이 쳐줍니다.

 

$ nssm.exe install

그럼 gui가 뜨고, 알맞은 parameter들을 입력합니다.

console.log를 print할 수도 있습니다. (io tab을 통해)

 

여기서 error 가 떠서 고생했었는데, 알고보니 Python script를 

node가 부르는 과정에서 (spawn)

그냥 python을 부르는 것이 아니라, python path를 포함한 파일을 설정해줘야 하는 것을 디버깅 했습니다.

 

이후, 2주마다 logging을 할 수 있는 winston이라는 program을 깔고,

winston은  winston과 winston-daily-rotate-file 둘 다 깔아줘야 하고,

포맷도 입맛대로 맞춰서 록깅할 수 있습니다.

 

ref:

https://www.npmjs.com/package/winston-daily-rotate-file

https://harjinderkamboj.wordpress.com/2012/09/06/running-node-as-a-service-using-nssm-2/

반응형