Plesk Node.Js Setup

How to Work with Node.js Apps on Plesk Obsidian

If you’re interested in hosting Node.js apps, we’ve got good news for you. Plesk comes with a Node.js extension that allows you to manage apps easily. In this article, we’ll describe in detail how to work with Node.js apps in the context of Plesk Obsidian, the latest version of Plesk.

Prerequisites

The first thing you need to do is install Plesk Obsidian. I chose Debian as the server OS for this article. You can use either a Linux distro or Windows – just note that there could be some minor differences if you go with a different OS. Assuming Plesk is already installed, let’s install the Node.js extension. 

Log in to Plesk, go to “Tools and Settings”, and click “Updates and Upgrades”. Next, go to “Add/Remove Components”. Find the “NodeJS support” component. Select it, and continue with the Node.JS installation. In a few minutes, all the necessary components will be installed and you’ll be ready to go!

Prerequisites - Install NodeJS on Plesk

Hosting a ‘Hello World’ App

To make sure everything works, let’s try to host a sample Node.js app, such as a “Hello, World” app. You can download one here. Copy/pasting the contents of the app.js file manually is an option. But I suggest trying out another Plesk extension instead – namely, the Git extension

First, you have to create a subscription (a domain with hosting). Then, you need to create a target directory where the app will be stored. Select your subscription, go to the “Files” tab, and create a directory named “hello-world”. Next, go to the “Domains” tab, choose the website, and click the “Git” button.

Local Repo Set Up

Now, you’ll learn how to set up a local repo as a mirror of a remote one, and deploy the code to the previously created directory. Set this URL as the remote Git repo URL, and change the target to the “hello-world” directory. The settings should look like this:

Local Repo Set Up

Differences Between ‘Document Root’ and ‘Application Root’

The next step is to change the “Document root” for the domain. Notice that I’ll be talking about  “Document root” and “Application root”: they aren’t one and the same. When we’re talking about web apps (e.g. Node.js based apps or similar), the “Document root” is the location where the static assets can be found. Meanwhile, the “Application root” is the root directory where the app itself is located. In most cases, the “Document root” is a directory inside the “Application root” directory (e.g. “public”). 

You need to change the document root now. To do so, go to “Domains”, select your website and go to “Hosting Settings”:

Differences Between ‘Document Root’ and ‘Application Root’

Change the existing document root to ‘hello-world/public’ (without quotes) and click the ‘Ok’ button to save the changes.

Hosting settings for Node.Js app - Plesk

Enable Node.js Support

The last thing to do before you run the app is to enable Node.js support on the domain. Go to “Domains”, choose the website and click “Node.js”. Here you’ll see some information about your app and a row of buttons on top. Click “Enable Node.js”, and in a few seconds, your screen will look like this:

Enable Node.js Support

First, let’s click on the “Application URL” link to make sure that the app is running. If you see a “Hello, World!” message, congratulations! Your Node.js app is up and running.

App with Dependencies

Real-world Node.js apps always have external dependencies defined in the package.json file and installed in the node_modules directory. 

Let’s take a look at an Express-based app – you can download it from the repository here. Either repeat the steps above to set up a repository in Plesk, or download/upload the source code manually. Once you’re done, the Node.js settings screen should look like this – assuming you uploaded the code to the “express-demo” directory:

Node.JS App with Dependencies

Installing Dependencies

Before you try accessing the app, you need to initialize it first. Let’s begin by installing dependencies – luckily, in Plesk, it’s as easy as clicking the “NPM install” button. This will install all app dependencies according to the package.json file. Then, you need to tune the app startup file. Plesk uses the Phusion Passenger application server to serve Node.js apps. Our demo app repository contains a file named “server.js”. This file is not a part of a typical Express-based app and contains just a few lines of code, but it’s nonetheless necessary for the app to run:

const app = require('./app');
const http = require('http');

http.createServer(app).listen(process.env.PORT);

You can use the idea behind this file when hosting other Node.js apps (e.g. based on a different framework). The last thing you need to do is to change the “Application Startup File” setting to “server.js”.

Installing Dependencies - App with Dependencies - Work with Node.js Apps in Plesk Obsidian - Plesk

Now, try browsing the domain on which you installed the app – you should see the Express welcome message.

By default, the app is running in the “production” mode. If you modify the app, don’t forget to restart it by clicking the “Restart” button.

Debug

Knowing how to debug Node.js apps in case any issues appear is essential for a Node.js developer. Here are a few tips that can save you a lot of grief: 

Log Files Checkup

The first thing to do when troubleshooting a Node.js app is to check the log files. For example, if you forget to install the dependencies for the demo Express app (you do it via the “NPM install” button, remember?), the Apache error log will contain the “Cannot find module ‘express’” error. Unfortunately due to Phusion Passenger nature, the server-wide error log is used instead of per-domain error logs. In this case, end-users will see the following message:

Log Files Checkup

Bring Error Messages to the Browser

When developing an app, it’s very handy to see the error messages directly on the site – they are still getting logged. Go to the Node.js app settings screen and change the Application Mode to “development”. Next time an issue pops up, the error will be shown in the browser window. Like this:

Bring Error Messages to the Browser - Debug - Work with Node.js Apps in Plesk Obsidian - Plesk

Moreover, if your app is running in the “development” mode, you don’t need to restart the app every time you modify the contents of a file.

Node.js and Windows

Node.js support is available in both Plesk for Linux and Plesk for Windows. But hosting Node.js apps on Windows has a few caveats you need to take into account. 

First, Node.js support in Plesk Obsidian is implemented with the help of the iisnode module (if you would like to learn more about the iisnode project, you can find the documentation here). Second, while in Plesk for Linux you can select a different Node.js version for every domain. In Plesk for Windows, a single Node.js version is used server-wide – you can select the Node.js version during the installation. 

Testing Node.js Support

Another difference is the location of the main entry point. In Plesk for Linux, it must be located in the parent directory of the domain’s “Document root”. In Plesk for Windows, it must be placed directly in the “Document root” directory.

To test Node.js support, let’s use the Express-based demo app from here. Create a directory called “node-express” on your domain using FTP access or the built-in File Manager. Then deploy the contents of the “node-express” GitHub repository. After that, click the “Hosting Settings” link (inside Domains -> Website name) and set the domain’s “Document root” directory to “node-express”.

Testing Node.js Support - Node.js and Windows - Work with Node.js Apps in Plesk Obsidian - Plesk

Then, go to Node.js app settings and change the “Application Startup File” to “server.js”. Finally, install the dependencies using the “NPM install” button. Once the dependencies are installed, you can browse your site to make sure that the app is running. Some additional tuning of rewrite rules may be required, but as you can see, it’s possible to launch Node.js app even on Windows hosting.

…So that’s it, folks! Plesk Obsidian and Node.js support extension make hosting Node.js apps as simple as one, two, three. You can also read Php vs Node.js and Node.js vs Ruby on Rails comparison articles for more information. Now, give it a try and let us know how you did in the comments! 

How useful was this post?

Click on a heart to rate it!

Average rating 3.4 / 5. Vote count: 28

No votes so far! Be the first to rate this post.

Oh no, sorry about that!

Let us know how we can do better below

Tell us how we can improve this post?

About

Avatar
Alexei has been part of the Plesk team since 2005 and is the Plesk Core team's Unit Manager. He's passionate about programming, product development and driving tech teams.
    Showing 73 comments
    • Avatar
      Kuno
      Reply

      Where is the log file?

      • Avatar
        Alexei Yuzhakov
        Reply

        In case of Debian/Ubuntu you can find Phusion Passenger output inside /var/log/apache2/error.log

        • Avatar
          Diederik
          Reply

          And in other cases ?

    • Avatar
      Constantinos Sergiou
      Reply

      hello i have added the hello word example and i follow the steps you say but i still not see the example

    • Avatar
      Antonio Sánchez
      Reply

      That is so awesome! Setting up a Node app was really easy. Plesk is helping us spare so much time managing our servers.

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Thanks for the feedback Antonio 🙂

    • Avatar
      Gopakumar
      Reply

      I upgraded Plesk from Odin to Onyx.

      Added Phusion Passenger server and NodeJS Support.

      Did a helloworld scrpit in app.js but all I can see is Apache default page.

      `ps x` shows two instances of Passenger Core and Passenger Watchdog but no sign on Node

      What could be wrong?
      Any help appreciated…

      • Avatar
        Plesk
        Reply

        Hello Gopakumar, are you still having this problem? Please get in touch with us, so we can find a solution: https://www.plesk.com/contact-support

      • Avatar
        Plesk
        Reply

        Hello Gopakumar, are you still having this problem? Please get in touch with us, so we can find a solution: https://www.plesk.com/contact-support

        • Avatar
          Gopakumar
          Reply

          Thank You, I got support from Plesk. The issue got resolved. They figured out that the hello world app will work only if the Document Root and the App Root need to be same, But another example worked just fine.

          • Avatar
            Plesk
            Reply

            Great to hear, Gopakumar!

    • Avatar
      Dietmar Leher
      Reply

      It would be nice to update the versions in the extensions to the latest ones, especially v7 is outdated.

    • Avatar
      Saleem Ansari
      Reply

      hey guys i have installed node js on plesk onyx server… and laso created subdomain bt still not able to run node app please help me…

    • Avatar
      Diederik
      Reply

      Hi there,

      I successfully installed the nodejs extension and I’m currently using it to run a websocket (using socket.io).
      The problem is I get 400 errors on the ws handshake and the server always falls back to polling.

      The reason for this appears to be that nginx is unable to forward the http upgrade request to the node server.

      Similar discussions:
      https://www.nginx.com/blog/websocket-nginx/
      https://github.com/socketio/socket.io/issues/1942
      https://talk.plesk.com/threads/websocket-error-400-docker-nginx.342596/

      Question is: how can find the address/port the node process is running on ?
      I tried using top, node, … but I’m unable to find the actual process.
      Can anyone point me in the right direction ?
      Thanks !

      • Avatar
        Diederik van Remoortere
        Reply

        SOLVED: I had to disable nginx + php

    • Avatar
      Diederik van Remoortere
      Reply

      hi,

      I’m experiencing weird behaviour using nodejs on my plesk server.
      It appears something is blocking the nodejs execution. I’m not sure what…
      When I set up a basic server and run a setInterval function to log date time every second, the code gets executed but every few seconds the output to the console lags for a couple of seconds and then outputs the (buffered ) console messages …

      I’m just tailing the log file with tail -f
      when I do a top I see passenger is only taking max 1% of my CPU…

      setInterval(function(){
      console.log(‘1sec’, new Date().getTime());
      }, 1000);

      any ideas what could be the cause of this ?

    • Avatar
      طراحی سایت
      Reply

      hey guys i have installed node js on plesk onyx server… and laso created subdomain bt still not able to run node app please help me…

    • Avatar
      Roberto
      Reply

      Hello,
      how to remove application from single domain ? After create it is not possible remove or reinstall .

    • Avatar
      david chemla
      Reply

      Is it possible to keep apache / ngix & PHP server and to have nodejs running separately in another folder ?

    • Avatar
      Manoochehr
      Reply

      Important :
      I have several days of disappointment … AND …

      maybe this helps you :
      You should disable proxy mode. (drop off the apache from request pipeline)

      When proxy mode is on this is the thing happening :
      nginx —> apache —> node (express server for example)

      with above config (default) the phusion passenger (process manager) fails to reset your app.

      you should uncheck the proxy mode inside your domain / apache and nginx settings

      and everything will go well after that.

      I wonder why it’s not mentioned in the guide

    • Avatar
      Kris
      Reply

      Installing and running Node.js on Plesk was simple thanks to this tutorial.

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Thanks Kris!

    • Avatar
      Angelo
      Reply

      For some reason the app.js isnt started at all – also when clicking on restart application.
      I now added a startup script into init.d to do that… However it would be nice to figure out why it will not get called…

    • Avatar
      Werner
      Reply

      How i can call Commands like „Run Script“ or „Restart App“ via XML-API ?
      i‘m not able to find documentation about that…. any help is welcome!
      regards
      Werner

    • Avatar
      John
      Reply

      For some reason my app occasionally is getting killed when I start it from plesk panel. How is plesk running the commands from the ui?

      • Avatar
        ayuzhakov
        Reply

        It’s more about Phusion Passenger application server rather than about Plesk. Technically speaking Plesk creates (or touches) a special file (tmp/restart.txt), Phusion Passenger starts or restarts the app on the HTTP next request.
        Try to start with an example app and try to find the difference between your app and the example app.

    • Avatar
      piccosoft
      Reply

      Your blog is very nice… Thanks for sharing your information…

    • Avatar
      Thomas W Tupper
      Reply

      I’m struggling to deploy a react app built using create-react-app, and I’m wondering if there is a tutorial out there anywhere. The structure of a react app created using create-react-app seems diametrically opposed to that which is expected by Plesk, and frankly I’m not sure how to adapt it or if it is even possible. However, given that this is the most popular method for bootstrapping a react app at present, it would be nice if Plesk could address this. So far as I can tell, there aren’t even any react tutorials, period.

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Will look into this suggestion Thomas, thanks for your input!

    • Avatar
      Liam
      Reply

      Hi when i try this I get the following error
      Cloning Git repository node-hello-world.git…
      fatal: unable to access ‘https://github.com/plesk/node-hello-world.git/’: Peer reports incompatible or unsupported protocol version.

      Ive also tried it from different repos and get the smae error. Any solution to this is most welcome!

    • Avatar
      Ebrahimi
      Reply

      Hi, using plesk, onyx, node-js and express, how is it possible to get user ip address, while every things return “undefined”

      res.status(200).json(‘x-forwarded-for: ‘+req.header(‘x-forwarded-for’)+’, remoteFamily: ‘+req.connection.remoteFamily+’, remoteAddress: ‘+req.connection.remoteAddress+’, remotePort: ‘+req.connection.remotePort).end();

    • Avatar
      Sunil Krishnan
      Reply

      Deos plesk interfere with issnode and iiis on a windows machine /

      One of my nodejs app doesnt work on a windows 2012 server where plesk is installed.

      iisnode moldule says it cant find node.exe to run..I installed iisnode independently not thru plesk.

      Is this possible ?

    • Avatar
      daniel
      Reply

      Hi,

      1. Does NodeJs work on multiple cores like when using pm2?
      2. How can we add a Additional deployment actions: that restart the app and also npm install. currenty I add to Additional deployment actions: touch tmp/restart.txt but it does not restart the app and will not do npm install.
      3. When do you plan to release compability with nodejs 10.15.0 LTS?

      Thanks for your great job

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey Daniel, are these questions still unanswered or have you found a solution? Get in touch with support: https://www.plesk.com/contact-support so we can help you further 🙂

    • Avatar
      dietcheese
      Reply

      In my experience, Node does not automatically restart when in development mode.

      The only way I have found that consistently works on Plesk is this command:

      touch tmp/restart.txt

      What’s worse is that it takes about 5-6 seconds before Node finishes restarting, using the touch method.

      My takeaway is that a Plesk server is the wrong place to do Node development or testing.

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Thanks for your input anyway, we’ll raise this issue.

    • Avatar
      Reply

      I enabled all NodeJs features but i can’t show NodeJs below my subscribe. How should I do?

      • Avatar
        Alexei Yuzhakov
        Reply

        You can double check Node.js extension (Extensions -> My Extensions -> Node.js) and Node.js support (interpreters) as well as Phusion Passenger are installed. If nothing doesn’t help, you can try to contact support: https://www.plesk.com/contact-support

    • Avatar
      Poh
      Reply

      Hi, May I know does Plesk panel support node cluster?
      https://nodejs.org/api/cluster.html

      thanks!

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey Poh, Plesk doesn’t officially support NodeJS 11 yet, but if you have it on the system, it can be registered in Plesk. So technically, you CAN use it together with Plesk, however it won’t be supported. Note that the Node Cluster module is incompatible with Passenger. In other words. Plesk runs Node JS with Passenger module, therefore, it’s not possible to invoke/call/import the Node Cluster module in the application due to incompatibility. Hope this helps. For further info, check out our article on NodeJS versions in Plesk.

    • Avatar
      Marcel
      Reply

      When trying to run the express demo I always end up with a 404 error, with the following error message:
      Not Found

      404

      Error: Not Found
      at …./Expressdemo/app.js:33:13
      at Layer.handle [as handle_request] (…/Expressdemo/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (…./Expressdemo/node_modules/express/lib/router/index.js:312:13)
      at …/Expressdemo/node_modules/express/lib/router/index.js:280:7
      at Function.process_params (…./Expressdemo/node_modules/express/lib/router/index.js:330:12)
      at next (…/Expressdemo/node_modules/express/lib/router/index.js:271:10)
      at …./Expressdemo/node_modules/express/lib/router/index.js:618:15
      at next (…./Expressdemo/node_modules/express/lib/router/index.js:256:14)
      at Function.handle (…./Expressdemo/node_modules/express/lib/router/index.js:176:3)
      at router (…./Expressdemo/node_modules/express/lib/router/index.js:46:12)

    • Avatar
      Rahmat Ali
      Reply

      If someone is successfully installed the app and cannot be able to use URL other than home one (it can be included to the scripts or styles home page is requesting for), you have to change the “web.config” file, which can be found in your “document root” directory.

      Add the content on your behalf, following the tutorial from:

      https://tomasz.janczuk.org/2011/08/hosting-express-nodejs-applications-in.html

      I have changed the line (from the tutorial):
      From :

      To:

      It’s now working fine for me. Now, my application is targeting all of the URLs to my main app.js file.

      Hope it will solve your hours or days, I have wasted to solve it.

      Thanks,

    • Avatar
      Elena
      Reply

      Hello, after installation i dont found app.js tell me file not exist. what i can do?

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey Elena, have you been in touch with our support team?

    • Avatar
      Adi
      Reply

      Hello, I have a Node app with Angular and Express. It works on a Node server but I am having problems running it in Plesk. Is it possible to such type of apps in Plesk?

      Thanks

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey Adi,

        Angular is a javascript related, it’s not related to Node.js, so yes, it will work. Like any other javascript libraries – example react.js, voe.js and so on. Hope this answers your question 🙂

        • Avatar
          Adi
          Reply

          Hello Debbie,
          Thanks for your response. I’m with a hosting plan that uses Plesk. I have a node app that uses Express and Angular that I’m having problems getting it to work using Plesk but the exact same code runs fine on a Node server. I can send you the links if necessary. So if you have any information on hosting such apps (MEAN, MERN or MEVN) on Plesk, please let me know.

          Thanks,
          Adi

    • Avatar
      Mark
      Reply

      Great tutorial. I am using the newer version of onyx – obsidian. I don’t see a “NPM” button in order to install the dependencies for the express portion. Is it hidden somewhere?

      Thanks,
      Mark

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey Mark, thanks for your feedback.
        You don’t see the NPM button because the application root directory does not contain the package.json configuration file.
        Once there is package.json in the application root directory, the button “NPM install” should appear in domain’s Node.js menu.
        If you continue to have issues, please contact our support: https://support.plesk.com/hc/en-us

    • Avatar
      Christian
      Reply

      Can you please update this? The issue that I am having is that I cannot change the section where it says “Access to Configuration Files” whenever I try to click it, it opens up the incorrect file and won’t allow me to change where it is pointing.

    • Avatar
      Hmm
      Reply

      It’s really disappointing that this is the only decent documentation for the extension at all

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hey, thanks for your feedback. What information are you missing specifically? So that we can make sure to provide it 🙂

    • Avatar
      Björn
      Reply

      I’m trying to install a GatsbyJS site and am running into all kinds of errors. I also don’t have NPM command available via SSH?
      Is it even possible to install a GatsbyJS site with this extension?

    • Avatar
      Tim Hosking
      Reply

      I’m trying to install a ReactJS app on Plesk Obsidian, but Plesk complains ‘Application will not work because document root is not a subchild of application root’. ReactJS doesn’t organise projects in the way Plesk expects, so it’s a real show stopper. Why is this restriction in place and how can I work around it?

      • Debbie from Plesk
        Debbie from Plesk
        Reply

        Hi Tim,
        Both document root and application root can be changed, this blog actually helps you configure them properly.
        Unless this application is a React.JS application with Server-Side Rendering which uses Electron/http.createServer, then there’s no need to configure it in the “Domains > example.com > Node.JS” menu. Just run “npm build” and set up a proper document root (directory “httpdocs/build”) instead.

        1. Run “npm build” to build the production-ready version of the code as suggested in react-create-app readme
        2. Upload files on server
        3. Change document root if needed

        Hope this helps! If not, please get in touch with our support 🙂

    • Avatar
      Gillian
      Reply

      Thanks for the great tutorial.
      I followed the directions, but since I’m on OVH as my plesk provider, the “NPM start” button didn’t appear. Also I don’t have root privileges on this server.
      I had a problem installing the dependencies of the “express” demo. So I created a clone of this repo in which I included the dependencies (node modules) then I used this repo as a source on the server and it worked.
      Do you think that by using the same method I will be able to run my own API?

      • Avatar
        Alexei Yuzhakov
        Reply

        Thank you for your support. Did you mean “NPM install” button? It depends on presence of package.json file. Absence of root privileges is not a problem if provider installed the components properly (Node.js interpreter and Phusion Passenger). If you have problems even with express demo app and dependencies installation seems like Node.js interpreter is absent and it’s better to contact OVH.

        • Avatar
          Gillian
          Reply

          Yes, sorry. I was well talking about “NPM install” button, which wasn’t displaying with the express demo. And in both (express demo and my project a package.json is included). So I think I need to take this up with OVH. But when I asked them earlier, they said they don’t provide support for those aspects…
          I will try again.
          Thank you very much for your help!

    • Avatar
      Mousa Khalil Saleh
      Reply

      Hi
      I noted that my node js app is not running after one day automatically.
      Dose that happening in normal or I have to change some settings.

      Is there vedio showing all steps?
      Is it important to send requests to node server every day to be running all the time?
      I can se that my node js server is running on all ports, not on the port that i choosed on localhost.

    • Avatar
      Julian
      Reply

      I just plesk on windows, I can’t find the option to define environmental variables.

      Your comment is awaiting moderation.

      • Laura from Plesk
        Laura from Plesk
        Reply

        Hi Julian! Could you address your issue to our support channel, please? Our support team will be able to help you with it. Thank you!

      • Avatar
        Alexei Yuzhakov
        Reply

        This functionality exists only on Plesk for Linux.

    • Avatar
      Bruce Ba
      Reply

      Worked perfectly!

    • Avatar
      Sarita Saha
      Reply

      Hi, As per the article, when I am trying to set the Document Root as “/public”, then I am getting the 404 error. Can anyone please help me with this?

      • Avatar
        Alexei Yuzhakov
        Reply

        Usually, it means some kind of misconfiguration and the webserver tried to access the location but there is no any handler or index.html (not relevant for our case). E.g. Node.js was not enabled or misconfigured on the domain. Webserver log files can be helpful to understand the reason.
        If you can’t solve the problem by yourself, you can try to reach our support: https://www.plesk.com/contact-support

    Leave a Comment

    Start typing and press Enter to search