How to use a Node.js application on cPanel hosting

Procédure

What is Node.js?

Node.js is an open-source, cross-platform runtime environment that lets you create a website or application and host it on a server, using the JavaScript language. On our cPanel and CloudCP packages, we provide you with the Node.js application manager so you can set up a Node.js application on your cPanel web hosting package. Node.js versions 6.x to 20.x are available.

What is Phusion Passenger?

To provide our customers with a stable and robust environment for Node.js, we integrate your Node.js applications with the Apache web service using the Phusion Passenger tool.

We do not set up a reverse proxy, and Node.js applications cannot run standalone on their own web server. If you are used to running your Node.js server with a command such as npm run start or pm2 start myapp, you will not be able to do this on our cPanel hosting packages. If you use a framework, find out whether it is compatible with Phusion Passenger.

How do I install a Node.js application?

Connect to your cPanel management interface and click on the"Setup Node.js App" icon.

How to use a Node.js application on cPanel hosting

On the page that follows, click on the"Create Application" button to add a new application.

How to use a Node.js application on cPanel hosting

Then fill in the fields as required for your application:

  • Node.js version: the version of Node.js your application requires.
  • Application mode: allows you to define the execution mode of your application, either developer mode or production mode. This manipulates the NODE_ENV environment variable, allowing errors to be displayed in developer mode (which is useful for debugging purposes, but can also be problematic for a production application).
  • Application root: the location of your Node.js application, relative to your FTP root. We recommend that you do not put your Node.js application in the public_html folder.
  • Application URL: the root URL of your Node.js application.
  • Application startup file: the name of the .js file that Passenger will send to Node.js to start your application.

How to use a Node.js application on cPanel hosting

Then click on the"Create" button once your application has been set up.

If your application startup file does not yet exist, the tool will immediately create this file with sample content. This example will display " It works! " on all HTTP requests associated with it.

Here are the contents of this example script :

var http = require('http'); var server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); var message = 'It works!\n', version = 'NodeJS ' + process.versions.node + '\n', response = [message, version].join('\n'); res.end(response); }); server.listen();

You can also edit the package.json file from the interface to add dependencies and install these dependencies using the " Run NPM Install " button:

How to use a Node.js application on cPanel hosting

Note that you need to restart your application if its dependencies have been modified.

You can also define environment variables in the Environment variables section if your application relies on them to obtain certain parameters.

Accessing your application from the terminal

Using the command line terminal is an integral part of the Node.js ecosystem. To access your application's environment from the terminal, connect to it (from the cPanel web terminal or from an SSH client) and copy the command shown to enter your application's environment:

How to use a Node.js application on cPanel hosting

This action will automatically activate the correct virtual environment for your application, including the correct version of Node.js and NPM, as well as the dependencies installed in the environment (instead of being installed in the " node_modules " folder in your applications folder).

Debugging a Node.js application

To debug a Node.js application, you can consult the Apache error log. The Apache error log file contains :

  • STDOUT and STDERR output from the Node.js application
  • Passenger-related errors
  • Apache-related errors

If you have manually set the PassengerLogFile value in your site's .htaccess file, the STDOUT and STDERR output and Passenger-related errors are sent to this file instead of the Apache log file.

You can also set the PassengerFriendlyErrorPages value to on in your .htaccess file to display errors relating to the start-up of your Node.js application directly on the web browser.

Common Node.js errors

Error: /lib64/libstdc++.so.6: version 'CXXABI_X.X.X' not found

Possible reasons: Your Node.js application (or one of its dependencies) requires specific functionality in the C++ library, which is not currently present on the server in question. This can happen on our cPanel formulas with the CloudLinux 7 operating system (an operating system based on CentOS / RHEL 7) whereas one of your dependencies requires RHEL 8 / CentOS 8 or later.

Solution: You can open a support request to ask to be migrated to a server with a CloudLinux 8 operating system.

Process stopped when running npm install

Possible reasons: Your process may be stopped by the server if it is running beyond the execution time and/or quantity of resources (CPU, RAM, etc.) authorised on your hosting package. You can view the process stop history using our " Logs " tool available from your cPanel interface.

Solution: You can limit the RAM memory used by npm using the NODE_OPTIONS environment variable as follows:

NODE_OPTIONS='--max-old-space-size=2048' npm install

This example shows, for example, a limit of 2048 MiB (2 GB).

Specified directory already used by /home/$USER/public_html/monapp when created from Setup Node.js App

Possible reasons :

  • A Node.js, Python or Ruby application published in the specified directory already exists.
  • Theroot application and the specifiedURL application point to the same folder.

Solution:

  • Check that no Node.js, Python or Ruby application is published on the specified folder. You can check the .htaccess file for the folder in question from the file manager or your usual FTP client to quickly identify this.
  • Make sure that your application files (.js, package.json ...) indicated by application root are not in the publication folder indicated by application URL. Unlike PHP applications, the files for a Node.js application do not need to and should not be located in public_html.

Rate this article :

3.2/5 | 14 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How to use a Python application on cPanel hosting

1mn reading

How to use a Ruby application on cPanel hosting


Questions sur l'article
ckothor7 Il y a 522 days
Peut-on deployer une application angular sur vos serveurs ??
See the
1 answers
Benjamin-LWS - Il y a 521 days

Bonjour,

Merci de votre retour.

Il est tout à fait possible de déployer une application sous Angular.js sur nos formules cPanel.

Pour ce faire, rendez-vous dans sur votre cPanel et chercher : "Softaculous Apps Installer"

Puis dans la nouvelle page qui s'ouvre, rechercher dans la barre de recherche en haut à gauche "Angular". Et vous pourrez installer Angular sur votre cPanel.

Je vous remercie de votre attention et reste à votre disposition pour toute autre question ou complément d'information.

Nous vous invitons à contacter notre service support à travers votre espace client, afin de vous apporter une aide si vous rencontrez des difficultés quelconque. (https://aide.lws.fr/a/268)

Cordialement, L'équipe LWS 

Utile ?
NourMaher Il y a 412 days
Pourquoi J'arrive pas a creer l'application???
See the
1 answers
Aurelien-LWS - Il y a 411 days

Bonjour, 

Je vous remercie pour votre message. 

Les raisons qui vous empêchent de créer ou de faire fonctionner une application Node.JS peuvent être nombreuses et nécessite d'avoir plus d'informations pour être analysé précisément.

Je vous invite à contacter notre équipe d'assistance technique depuis la rubrique "assistance" de votre espace client afin qu'un agent prenne en charge votre demande et résolve votre problème.

Cordialement, L'équipe LWS 

Utile ?

Ask the LWS team and its community a question