The Node.js App is finally ready! And now? You want to make the app available to the public? With Heroku or similar it works well, but then you have funny links. But we want to host the application on our server and deploy it on our own domain or subdomain. Here you can find out how this works in Plesk.
1. Upload Node.js files to target directory
Your program files must first be moved to where you want the app to run later. You can upload them to your directory via (S)FTP or Git repository. Important: The node_modules folder does not have to be uploaded!
2. Add Node.js extension to Plesk
On your Plesk interface you can install the extension Node.js under “Extensions”. Further you don’t have to set anything up for Node.js.
3. Activate Node.js for your domain or subdomain
Only one Node.js application can run per domain or subdomain. To start it, navigate to your domain and then to “Node.js”.
There you will find this view, on which we have to make some settings:
Node.js Version: Here we can normally select the latest version.
Document Root: This is the path where your application should be located.
Application Mode: You can choose between “development” and “production”. Since we want to publish our app, we set the value to “production”.
Application URL: We can’t change anything here, Plesk only shows us the address where our application can be reached.
Application Root: Here you have to select the directory where our app has the root directory.
Application Startup File: This is the most important file. The starting point for our program, i.e. the main JS file. Normally your app.js or index.js. If it is located in a subdirectory, the following value must be entered there: ./server/index.js.
Custom environment variables: You have the possibility to create environment variables for the app. These are variables that your program can read via process.env.VARIABLE. Often the port is specified here.
4. Install dependencies of our app
Now we click on “Enable Node.js” and then on “npm-Installation” to install all dependencies from our package.json. Our node_modules folder will be created again.
5. Restart App and Test
Now our application is ready. In order for the application to run correctly, we should press “Restart App” again. Then we can test our app via the corresponding link.
6. Configuring Apache & nginx
On my server the problem has occurred that my Apache has crashed permanently. This happened within the first few minutes after starting the Node.js application. I was able to fix this by disabling “Proxy mode”. You can find this setting under “Apache & nginx Settings” of the corresponding domain.
After deactivating this function, the Apache web server ran without problems.