Knowledge Base

How to make a simple 'Hello World' application using node.js on Plesk Onyx for Windows

This article demonstrates step-by-step how to create a simple application using node.js on Plesk Onyx for Windows. Differences between Plesk Onyx for Windows and other types of installations are highlighted.

Step 1: Access the Plesk control panel

To access the Plesk control panel, follow these steps:

  1. Log in to the Customer Portal.
    If you do not know how to log in to the Customer Portal, please see this article.
  2. On the Services menu, click MY SERVICES:

    Select My Services from the Services menu.

  3. To the right of the desired hosting package, click Manage.
  4. On the Hosting Information tab, click Open Control Panel.

Step 2: Set up the directory and file

To create the necessary directory and file, follow these steps:

  1. In the left sidebar, click Websites & Domains:

    Plesk - Sidebar - Websites and Domains

  2. Scroll to the management area for the domain where node.js is to be installed, and then click File Manager:

    The file manager icon and text.

  3. On the left side of the file manager is the directory tree. Click Home Directory.
  4. On the toolbar at the top of File Manager, click the New list box, and then click Create Directory:

    Image shows the home directory highlighted and the New list box open with the mouse pointer hovering over the Create Directory option.

  5. In the Create a Directory dialog box, in the Directory name text box, type hello_world, and then click OK:

    Create directory dialog with hello_world entered for directory name.

  6. On the directory tree at the left of File Manager, click the newly created hello_world directory:

    Image shows the hello_world directory selected.

  7. On the toolbar at the top of File Manager, click the New list box, and then click Create File:

    Image shows the New list box expanded with Create File

  8. In the Create a File dialog box, in the File name text box, type app.js, and then click OK:

    Image shows Create a File dialog box with apps.hs typed in the text box.

  9. In the right hand pane of the File Manager, click the name of the new file to open it in the code editor:

    apps.js shown in the file manager with mouse cursor ready to click

  10. Copy and paste the following code into the editor, then click OK:

    const http = require('http');
    
    http.createServer(function(request, response) {
      response.writeHead(200, {'Content-Type': 'text/html'});
      response.end('<H1>Hello World!</H1>');
    }).listen(process.env.PORT);
    
    console.log('App is running…');
    You may notice that this code sample is slightly different from other tutorials. The server.listen command typically names a port number (for example, server.listen(8000);) that starts a server listening for HTTP requests on port 8000. node.js for Windows must use the port provided by the iisnode module for IIS which is specified in the process.env.PORT variable.

Step 3: Configure node.js

To configure node.js and start the application, follow these steps:

  1. In the left sidebar, click Websites & Domains:

    Plesk - Sidebar - Websites and Domains

  2. Scroll to the management area for the domain where you want to install node.js, and then click the node.js icon. The node.js configuration page appears. Errors may appear on the page; they will be fixed in the following steps.

    The node.js icon.

  3. On the node.js configuration page, click the name of the Application Root. A directory tree dialog box appears.

    A partial view of the node.js configuration page detailing the Application Root configuration.

  4. In the directory tree dialog box, click the hello_world directory, and then click OK.

    The directory tree dialog box with the hello_world directory selected

  5. Still on the node.js configuration page, click the name of the Document Root. A directory tree dialog box appears.

    A partial view of the node.js configuration page detailing the Document Root configuration.

  6. In the directory tree dialog box, click the hello_world directory, and then click OK.

    You may notice that the Document Root is the same as the Application Root. This is different from other tutorials, where the document root is in a different location and typically contains static files. This is because the iisnode module for IIS consolidates the Document Root and Application Root and uses rewrite rules to direct requests for static files to a specific directory.
  7. Inspect the Application Startup File setting. It should be set to app.js by default. If it is not set to app.js, click the file name. The Application Startup File dialog box appears.

    A partial view of the node.js configuration page detailing the Application Startup configuration.

  8. Replace the name in the text box with app.js, and click OK.

    Dialog box showing the application startup file entered into the text field

  9. Click Enable Node.js. A confirmation message appears. You are now ready to test your first node.js application.

    The enable Node.js button

  10. Click on the Application URL. A new tab opens and displays the Hello World! page.

    A partial view of the node.js configuration page detailing the Application URL configuration.

More Information

For more information about Node.js, please visit https://nodejs.org.