How to create and run simple node.js application?

Created:

2017-02-13 22:29:36 UTC

Modified:

2017-08-08 13:14:01 UTC

0

Was this article helpful?


Have more questions?

Submit a request

How to create and run simple node.js application?

Question

How to create and run simple node.js application?

Answer

As an example of node.js application will be used the one which displays string Hello World in browser:

https://github.com/azat-co/nodejs-hello-world

1. Go to Plesk > Tools & Settings > Updates and Upgrades > Add/Remove Components and make sure that next components are installed:

Git and NodeJS support for Linux,

Git for WindowsNode.js IIS module (iisnode)Node.js and Node.js Engin (Node.js 6) for Windows.

2. Create a new subscription example.com via Plesk > Subscription > Add Subscription.

3. Go to Plesk > Subscriptions > example.com > Websites & Domains > example.com > Git and configure https://github.com/azat-co/nodejs-hello-world as a remote Git repository.

As a default it will pull and deploy all necessary application files automatically.

Check the article Using remote Git hosting to find how to manage Git feature.

4. For Linux go to Plesk > Subscriptions > example.com > Websites & Domains > example.com > Hosting Settings and change Document root to /httpdocs/public

For Windows this step is not required.

5. Go to Plesk > Subscriptions > example.com > Websites & Domains > example.com > Node.js and change Application Startup File to server.js instead of app.js.

6. For Windows edit the file httpdocs/server.js via Plesk > Subscriptions > example.com > Websites & Domains > example.com > File Manager in a certain way:

[before]

<...>
//outputs string with line end symbol
}).listen(1337, "127.0.0.1");
//sets port and IP address of the server
<...>

[after]

<...>
//outputs string with line end symbol
}).listen(process.env.PORT);                                                 //this row was changed
//sets port and IP address of the server
<...>

For Linux this step is not required.

7. Go to Plesk > Subscriptions > example.com > Websites & Domains > example.com > Node.js, click on Enable Node.js and then on NPM install to install necessary dependencies.

8. Node.js application is ready for running.

Open in a browser http://example.com.

The expected result should be the string Hello World.

Have more questions? Submit a request
Please sign in to leave a comment.