How to automatically reload Node.js project when using pm2

后端 未结 4 982
情深已故
情深已故 2021-02-02 10:58

I am currently programming Node.js with Express.js, and every time I change a line of code in the file router or app, I need to type the command:

pm2 reload id_         


        
4条回答
  •  广开言路
    2021-02-02 11:30

    pm2 is a Node process manager that has lots of bells and whistles. you can run the below command to automatically restarting the node application when file changes in the directory are detected.

    pm2 start index.js --watch
    

    Note that because pm2 runs things in the background, you can’t just ctrl+c your way out of a running pm2 process. You have to stop it by passing the ID or the name.

    pm2 stop 0
    pm2 stop index
    

    other two options are below

    npx supervisor index.js
    nodemon index.js
    

提交回复
热议问题