Node.js as a permanent service

Skip to main content
Du bist hier:
Drucken

Node.js as a permanent service

Are you running a Node.js application in Plesk that should run permanently, for example your own server, a bot or a monitoring tool? There are three typical pitfalls.

1. Startup file instead of «Run script»

If you start a permanent application with «Run script» (for example npm run start), the process keeps running with the Node.js version that was selected when you clicked. If you change the version later, the running process does not pick it up.

  • Instead, enter the Application Startup File for your Node.js application in Plesk, for example server/server.js.
  • Choose the Node.js version you want and click «Restart App».
  • This way Plesk manages the process itself and always starts it with the selected version.

If an old process started with «Run script» is still running, it has to be stopped once. Open a ticket if you cannot stop it yourself.

2. WebSockets do not work

By default your application runs behind a proxy that does not pass on WebSocket connections. Many applications then automatically fall back to another connection method and still work. If your application strictly requires WebSockets (for example the Node-RED editor), proceed as follows:

  • Open «Apache & nginx Settings» for the affected domain or subdomain.
  • In the nginx settings section, uncheck «Proxy mode» and save.

If your application also works without WebSockets, leave proxy mode switched on. Always test WebSockets directly in the application, a simple test with curl does not reliably show the problem.

Every change to these settings restarts the application. Depending on the application, it may be unavailable for a short time afterwards.

3. The application does not start by itself after a restart

Plesk only starts a Node.js application on the first request to the website, not automatically after a web server restart. For a service that should always run, create a task of the type «Fetch a URL» under «Scheduled Tasks» in Plesk that calls your application’s address every minute. This way the service starts again automatically after every restart.

Related Post