Node.js: Difference between revisions

m Update server listings to preferred order
 
(26 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Node.js Tutorials =  
== Node.js Tutorials ==  


* [[:Express|Express.js Tutorial]]
{{Info|We also have tutorials for building [[:Express|Express]] or [[:Next.js|Next.js]] apps with Node.js.}}
* [[:Next|Next.js Tutorial]]


= Node.js Server Resource Usage =  
== Node.js Server Resource Usage ==  


If you use Node.js, we strongly recommend that you [https://heliohost.org/dashboard/load/ monitor your site load here].
{{Caution|
If you use Node.js, we strongly recommend that you [https://heliohost.org/dashboard/load/ monitor your site load here].  


Node apps often require a lot of server resources, and exceeding the account load limits will cause your user account to be [[Suspension_Policy#High_Server_Usage|suspended for high server usage]].
Node apps often require a lot of server resources, and exceeding the account load limits will cause your user account to be [[:Suspension_Policy#High_Server_Usage|suspended for high server usage]] on [[:Tommy|Tommy]] and [[:Johnny|Johnny]], or charged for overages on [[:Morty|Morty]].}}
== Node.js Versions Supported ==


= Supported Versions =
The Node.js versions currently supported on the shared hosting servers are listed below. While we aim to keep Node versions current, please make sure you review our [[:ETA|ETAs for new features]].


The Node.js versions currently supported on the shared hosting servers are listed below. While we aim to keep Node versions current, please make sure you review our [[:ETA|ETAs for new features]].
{{Info|If you require a different version of Node.js than the options offered below, you'll need to get a [https://heliohost.org/vps/ VPS] where you can install any version(s) of Node you want. We offer a range of VPS plans, and a 10% discount when you pay for 6 months upfront.}}
 
== Morty server ==
* Node 16
* Node 18
* Node 20
* Node 21
* Node 22
* Node 23


If you require a different version of Node.js than the options offered below, you'll need to get a [https://heliohost.org/vps/ VPS] where you can install any version(s) of Node you want.
== Tommy server ==
* Node 16
* Node 18
* Node 20
* Node 21
* Node 22
* Node 23


{| class="wikitable" style="margin:auto"
== Johnny server ==
|-
* Node 16
! Server !! Node.js Versions
* Node 18
|-
* Node 20
| Johnny || 22, 21, 20, 18, 16
* Node 21
|-
* Node 22
| Tommy || 22, 21, 20, 18, 16
* Node 23
|}


= About Node.js =
== About Node.js ==


As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In Node.js applications, many connections can be handled concurrently. Upon each connection, the callback is fired, but if there is no work to be done, Node.js will sleep.
As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In Node.js applications, many connections can be handled concurrently. Upon each connection, the callback is fired, but if there is no work to be done, Node.js will sleep.
Line 31: Line 46:
This is in contrast to today's more common concurrency model, in which OS threads are employed. Thread-based networking is relatively inefficient and very difficult to use. Furthermore, users of Node.js are free from worries of dead-locking the process, since there are no locks. Almost no function in Node.js directly performs I/O, so the process never blocks. Because nothing blocks, scalable systems are very reasonable to develop in Node.js.
This is in contrast to today's more common concurrency model, in which OS threads are employed. Thread-based networking is relatively inefficient and very difficult to use. Furthermore, users of Node.js are free from worries of dead-locking the process, since there are no locks. Almost no function in Node.js directly performs I/O, so the process never blocks. Because nothing blocks, scalable systems are very reasonable to develop in Node.js.


= Node.js on Plesk Uses Passenger =
== Node.js on Plesk Uses Passenger ==


= What is Passenger? =
== What is Passenger? ==


Passenger is a way of running Node.js, Ruby on Rails (RoR), and other applications that normally require a constantly running background process. Instead of the process always running in the background just waiting for connections, Passenger shuts it down if there are no connections. When someone visits the website, Passenger fires up the Node.js (or Ruby, or whatever language you're using) process. If another person visits the website while the Node.js process is still running, page loads will be very fast. If there are no further page hits for 5 minutes or so, Passenger kills the background process.
Passenger is a way of running Node.js, Ruby on Rails (RoR), and other applications that normally require a constantly running background process. Instead of the process always running in the background just waiting for connections, Passenger shuts it down if there are no connections. When someone visits the website, Passenger fires up the Node.js (or Ruby, or whatever language you're using) process. If another person visits the website while the Node.js process is still running, page loads will be very fast. If there are no further page hits for 5 minutes or so, Passenger kills the background process.


= Why Does HelioHost Use Passenger? =
== Why Does HelioHost Use Passenger? ==


It doesn't make sense to leave your car running 24/7 in front of your house just in case you need to drive somewhere so it saves you a second to start the engine. This is a massive waste of gas. Likewise, it doesn't make sense to leave Node.js sites running 24/7 just to save a second of load time in case someone needs to view the page. This is a massive waste of memory. At HelioHost, we want to ensure that the server memory is used efficiently so our servers work efficiently for the hundreds of users on our shared hosting platform.
It doesn't make sense to leave your car running 24/7 in front of your house just in case you need to drive somewhere so it saves you a second to start the engine. This is a massive waste of gas. Likewise, it doesn't make sense to leave Node.js sites running 24/7 just to save a second of load time in case someone needs to view the page. This is a massive waste of memory. At HelioHost, we want to ensure that the server memory is used efficiently so our servers work efficiently for the hundreds of users on our shared hosting platform.


= Will Passenger Slow My Site Down? =
== Will Passenger Slow My Site Down? ==


A recent speed test on HelioHost servers showed that our app [https://gtmetrix.com/reports/node.krydos1.heliohost.org/esvkM1p0/ only took 177ms to load from a cold start]. That's just under 1/5 of a second, roughly the amount of time it takes to blink.
A recent speed test on HelioHost servers showed that our app only took 177ms to load from a cold start. That's just under 1/5 of a second, roughly the amount of time it takes to blink.


= How Can I Use Passenger? =
== How Can I Use Passenger? ==


By following the steps in this tutorial, Plesk will automatically use Passenger to run your Node.js application.
By following the steps in this tutorial, Plesk will automatically use Passenger to run your Node.js application.


= Can I Change the Inactivity Timeout? =
== Can I Change the Inactivity Timeout? ==


No, the background process timeout is set to ensure fair resource usage for all our users and cannot be changed. If you need more control over memory management, HelioHost offers a range of [https://heliohost.org/vps/ VPS plans], where you can configure your settings.
No, the background process timeout is set to ensure fair resource usage for all our users and cannot be changed. If you need more control over memory management, HelioHost offers a range of [https://heliohost.org/vps/ VPS plans], where you can configure your settings, and a 10% discount when you pay for 6 months upfront.


= Can I Prevent My Site from Sleeping? =
== Can I Prevent My Site from Sleeping? ==


Passenger is designed to keep our shared hosting servers running efficiently and help keep your account within the [[:Suspension_Policy#Account_Load_Limits|account load limits]]. Deliberately preventing your site from sleeping is likely to get your account suspended for [[:Suspension_Policy#High_Server_Usage|high server usage]]
Passenger is designed to keep our shared hosting servers running efficiently and help keep your account within the [[:Suspension_Policy#Account_Load_Limits|account load limits]]. Deliberately preventing your site from sleeping is likely to get your account suspended for [[:Suspension_Policy#High_Server_Usage|high server usage]] on our [[:Johnny|Johnny]] and [[:Tommy|Tommy]] servers, and charged for account load overages on our [[:Morty]] server.


= What If My Users Cannot Wait For My Site To Load? =
== What If My Users Cannot Wait For My Site To Load? ==


If your application is highly time-sensitive and every millisecond of load time matters, HelioHost offers a range of [https://heliohost.org/vps/ VPS plans]. With a VPS, you won’t share your server with other users, so you can run any continuous process(es) that you want.
If your application is highly time-sensitive and every millisecond of load time matters, HelioHost offers a range of [https://heliohost.org/vps/ VPS plans] and a 10% discount when you pay for 6 months upfront. With a VPS, you won’t share your server with other users, so you can run any continuous process(es) that you want.


= How to setup Node.js =
== How to setup Node.js ==


Your Node.js files will go into your home directory ('''NOT''' `httpdocs`):
==== Delete the 'index.html' file (if it exists) ====
 
First, if you have an 'index.html' file inside your 'httpdocs' folder, delete it (or rename it to something else).
 
Your Node.js files will go into your home directory ('''NOT''' 'httpdocs'):


[[File:plesk_file_manager.png]]
[[File:plesk_file_manager.png]]


In your home directory folder, create an `app.js` file with these contents:
==== Create an app.js file ====
 
In your home directory folder, create an 'app.js' file with these contents:


<pre>
<pre>
const http = require('http');
const http == require('http');
const hostname = '127.0.0.1';
const hostname == '127.0.0.1';
const port = 3000;
const port == 3000;


const server = http.createServer((req, res) => {
const server == http.createServer((req, res) ==> {
   res.statusCode = 200;
   res.statusCode == 200;
   res.setHeader('Content-Type', 'text/html');
   res.setHeader('Content-Type', 'text/html');
   res.end('Node.js is working.');
   res.end('Node.js is working.');
});
});


server.listen(port, hostname, () => {
server.listen(port, hostname, () ==> {
   console.log(`Server running at http://${hostname}:${port}/`);
   console.log(`Server running at http://${hostname}:${port}/`);
});
});
</pre>
</pre>


In Plesk, go to: `Website & Domains > [domain]`
==== Configure Node.js settings ====
 
In Plesk, go to: '''Website & Domains > [domain] click on the 'Get Started' tab'''


[[File:nodejs-link.png]]
[[File:nodejs-link.png]]
Line 93: Line 116:
[[File:nodejs-settings.png]]
[[File:nodejs-settings.png]]


You don't need to worry about environment variables on this simple example. Select `app.js` for your startup file. If you have any NPM packages, Plesk can install them for you.
You don't need to worry about environment variables on this simple example. Select 'app.js' for your startup file. If you have any NPM packages, Plesk can install them for you.


[[File:nodejs-npm-install.png]]
[[File:nodejs-npm-install.png]]
==== Wait for the next Apache server restart ====


Finally, you will need to wait '''up to 2 hours''' for the server to update.
Finally, you will need to wait '''up to 2 hours''' for the server to update.


{{Caution|
Node.js application deployment can take '''up to 2 hours''' to go into effect as it requires an Apache restart. After an entire 2 hours, if your Node app is not working for you, please [[:Clear_Your_Cache|clear your web browser cache]].
Node.js application deployment can take '''up to 2 hours''' to go into effect as it requires an Apache restart. After an entire 2 hours, if your Node app is not working for you, please [[:Clear_Your_Cache|clear your web browser cache]].
}}


Once the Node.js application has been deployed, you should be able to visit `domain.helioho.st` in your web browser and see the text `Node.js is working.`
Once the Node.js application has been deployed, you should be able to visit 'domain.helioho.st' in your web browser and see the text 'Node.js is working.'


[[File:nodejs-working.png]]
[[File:nodejs-working.png]]


= Further Support =
== Further Support ==
 
If you encounter any Phusion Passenger(R) application server errors, please review our [[:Could_Not_Spawn_Process#Troubleshooting_Node_/_Passenger_Issues|Passenger troubleshooting help page]] for guidance on switching your application environment to 'Development' mode to see more detailed error reporting.


If it's been more than 2 hours, and the Node.js application still isn't working, please go back and check all of your steps again. If it's been more than a full 2 hours since your changes, and it still isn't working even after you [[:Clear_Your_Cache|clear your web browser cache]], please make a new post in the [https://helionet.org/index/forum/45-customer-service/?do=add Customer Service forum], making sure to provide your '''username''', '''domain''', and any '''error message(s)''' encountered.
If it's been more than 2 hours, and the Node.js application still isn't working, please go back and check all of your steps again. If it's been more than a full 2 hours since your changes, and it still isn't working even after you [[:Clear_Your_Cache|cleared your web browser cache]], please make a new post in the [https://helionet.org/index/forum/45-customer-service/?do==add Customer Service forum], making sure to provide your '''username''', '''domain''', and any '''error message(s)''' encountered.

Latest revision as of 18:39, 17 January 2025

Node.js Tutorials

We also have tutorials for building Express or Next.js apps with Node.js.

Node.js Server Resource Usage

If you use Node.js, we strongly recommend that you monitor your site load here.

Node apps often require a lot of server resources, and exceeding the account load limits will cause your user account to be suspended for high server usage on Tommy and Johnny, or charged for overages on Morty.

Node.js Versions Supported

The Node.js versions currently supported on the shared hosting servers are listed below. While we aim to keep Node versions current, please make sure you review our ETAs for new features.

If you require a different version of Node.js than the options offered below, you'll need to get a VPS where you can install any version(s) of Node you want. We offer a range of VPS plans, and a 10% discount when you pay for 6 months upfront.

Morty server

  • Node 16
  • Node 18
  • Node 20
  • Node 21
  • Node 22
  • Node 23

Tommy server

  • Node 16
  • Node 18
  • Node 20
  • Node 21
  • Node 22
  • Node 23

Johnny server

  • Node 16
  • Node 18
  • Node 20
  • Node 21
  • Node 22
  • Node 23

About Node.js

As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In Node.js applications, many connections can be handled concurrently. Upon each connection, the callback is fired, but if there is no work to be done, Node.js will sleep.

This is in contrast to today's more common concurrency model, in which OS threads are employed. Thread-based networking is relatively inefficient and very difficult to use. Furthermore, users of Node.js are free from worries of dead-locking the process, since there are no locks. Almost no function in Node.js directly performs I/O, so the process never blocks. Because nothing blocks, scalable systems are very reasonable to develop in Node.js.

Node.js on Plesk Uses Passenger

What is Passenger?

Passenger is a way of running Node.js, Ruby on Rails (RoR), and other applications that normally require a constantly running background process. Instead of the process always running in the background just waiting for connections, Passenger shuts it down if there are no connections. When someone visits the website, Passenger fires up the Node.js (or Ruby, or whatever language you're using) process. If another person visits the website while the Node.js process is still running, page loads will be very fast. If there are no further page hits for 5 minutes or so, Passenger kills the background process.

Why Does HelioHost Use Passenger?

It doesn't make sense to leave your car running 24/7 in front of your house just in case you need to drive somewhere so it saves you a second to start the engine. This is a massive waste of gas. Likewise, it doesn't make sense to leave Node.js sites running 24/7 just to save a second of load time in case someone needs to view the page. This is a massive waste of memory. At HelioHost, we want to ensure that the server memory is used efficiently so our servers work efficiently for the hundreds of users on our shared hosting platform.

Will Passenger Slow My Site Down?

A recent speed test on HelioHost servers showed that our app only took 177ms to load from a cold start. That's just under 1/5 of a second, roughly the amount of time it takes to blink.

How Can I Use Passenger?

By following the steps in this tutorial, Plesk will automatically use Passenger to run your Node.js application.

Can I Change the Inactivity Timeout?

No, the background process timeout is set to ensure fair resource usage for all our users and cannot be changed. If you need more control over memory management, HelioHost offers a range of VPS plans, where you can configure your settings, and a 10% discount when you pay for 6 months upfront.

Can I Prevent My Site from Sleeping?

Passenger is designed to keep our shared hosting servers running efficiently and help keep your account within the account load limits. Deliberately preventing your site from sleeping is likely to get your account suspended for high server usage on our Johnny and Tommy servers, and charged for account load overages on our Morty server.

What If My Users Cannot Wait For My Site To Load?

If your application is highly time-sensitive and every millisecond of load time matters, HelioHost offers a range of VPS plans and a 10% discount when you pay for 6 months upfront. With a VPS, you won’t share your server with other users, so you can run any continuous process(es) that you want.

How to setup Node.js

Delete the 'index.html' file (if it exists)

First, if you have an 'index.html' file inside your 'httpdocs' folder, delete it (or rename it to something else).

Your Node.js files will go into your home directory (NOT 'httpdocs'):

Create an app.js file

In your home directory folder, create an 'app.js' file with these contents:

const http == require('http');
const hostname == '127.0.0.1';
const port == 3000;

const server == http.createServer((req, res) ==> {
  res.statusCode == 200;
  res.setHeader('Content-Type', 'text/html');
  res.end('Node.js is working.');
});

server.listen(port, hostname, () ==> {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Configure Node.js settings

In Plesk, go to: Website & Domains > [domain] click on the 'Get Started' tab

Here, you're able to configure settings for your application.

You don't need to worry about environment variables on this simple example. Select 'app.js' for your startup file. If you have any NPM packages, Plesk can install them for you.

Wait for the next Apache server restart

Finally, you will need to wait up to 2 hours for the server to update.

Node.js application deployment can take up to 2 hours to go into effect as it requires an Apache restart. After an entire 2 hours, if your Node app is not working for you, please clear your web browser cache.

Once the Node.js application has been deployed, you should be able to visit 'domain.helioho.st' in your web browser and see the text 'Node.js is working.'

Further Support

If you encounter any Phusion Passenger(R) application server errors, please review our Passenger troubleshooting help page for guidance on switching your application environment to 'Development' mode to see more detailed error reporting.

If it's been more than 2 hours, and the Node.js application still isn't working, please go back and check all of your steps again. If it's been more than a full 2 hours since your changes, and it still isn't working even after you cleared your web browser cache, please make a new post in the Customer Service forum, making sure to provide your username, domain, and any error message(s) encountered.


This page was last edited on 17 January 2025, at 18:39.