Node-RED 系列(8)-- Using PM2 to keep Node-RED running on Windows

Node-RED running on Windows

Once installed, the simple way to run Node-RED is to use the node-red command in a command prompt. If you have installed Node-RED as a global npm package, you can use the node-red command:

image.png

This will output the Node-RED log to the terminal. You must keep the terminal open in order to keep Node-RED running.

Why using PM2

If you are using Windows to develop Node-Red flows or nodes, you may find it helpful to use PM2 to run Node-RED. This can be configured to automatically restart when files change, always keep Node-RED running and manage log output.

PM2 is a process manager for Node applications with monitoring, load balancing, automatic restart etc.
And it's perfect when you want to take your individual code and use all the CPUs on all the servers and keep the process alive forever.

Steps to using PM2 to keep Node-RED running on Windows

  1. Install PM2
    Execute the following at the command prompt:
    npm install –g –unsafe-perm pm2

    image.png

  2. Install and config pm2-windows-service
    Execute the following at the command prompt:
    npm i –g pm2-windows-service

    image.png

  3. Add environment variables for PM2


    image.png
  4. Install PM2 Service
    Open command line as administrator and execute below command
    pm2-service-install
    Tips: choose 'N' and continue, and then PM2 service install successfully

    image.png

    image.png

  5. Locate the Node-RED red.js File and add it to PM2
    Execute the following at the command prompt:
    pm2 start C:\Users\[replace with your user folder]\AppData\Roaming\npm\node_modules\node-red\red.js –n node-red

    image.png

  6. Save configuration
    Execute the following at the command prompt:
    pm2 save

    image.png

  7. Check status
    Execute the following at the command prompt:
    pm2 status
    pm2 info
    pm2 show

    image.png

  8. Restart pc and check PM2 status
    pm2 status

    image.png

That's all.
Hope this can help you!

你可能感兴趣的:(Node-RED 系列(8)-- Using PM2 to keep Node-RED running on Windows)