A simple ‘Hello World’ application with node.js on Plesk Onyx CP for Windows

In this article, we will highlight how to create a simple application using node.js on Plesk Onyx for Windows. Within the article there are differences between Plesk Onyx for Windows and other types of installations highlighted.

Step 1: Access the Plesk control panel

To access the Plesk control panel, follow these steps:

  1. Log in to the portal.
  2. On the Services menu, click MY SERVICES:
  1. To the right of the desired hosting package, click Manage.
  2. 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:

In the left sidebar, click Websites & Domains:

Scroll to the management area for the domain for the installation of node.js, and then click File Manager:

On the left side of the file manager is the directory tree. Click Home Directory.

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

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

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

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

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

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

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

const http = require('http');

createServer(function(request, response) {

writeHead(200, {'Content-Type': 'text/html'});

end('<H1>Hello World!</H1>');

}).listen(process.env.PORT);

console.log('App is running…');

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 the 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:

In the left sidebar, click Websites & Domains:

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.

On the node.js configuration page, click the name of the Application Root. A director

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 iismode module for IIS consolidates the Document Root and Application Root and uses rewrite rules to direct requests for static files to a specific directory.

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

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

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

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

Congratulations you’ve now learned how to create a new hello world application with plesk, Thank you for viewing this tutorial

Advertisements