In cPanel, Node.js is set up under “Setup Node.js App”. The tool offers 13 versions, from 10.24.1 to 24.x, and each application picks its own. The main point is this: the version must be the one your code expects, and if you change it, the dependencies have to be installed again. This article is about choosing the version and using npm. To get an application running from scratch, see getting a Node.js application running.
Choosing and changing the version
| 1 |
Find out what the project asks for. In package.json look for the engines field; if there is none, read the project README. An application built for a recent version may not even start on an old one.
|
|
| 2 |
Open “Setup Node.js App” in cPanel (Software section) and create the application, or open the one you have. In the Node.js version field pick the one the project asks for. For a new project the general rule is the most recent long-term support (LTS) version the list has; the support dates are on nodejs.org.
|
|
| 3 |
Pick the mode (development or production), the application root, the address, and the startup file. Save.
|
|
| 4 |
Install the dependencies: on the application screen, the “Run NPM Install” button reads package.json and installs. Do not upload the node_modules folder over FTP: cPanel manages it for you, in the application’s virtual environment.
|
|
| 5 |
Restart. The restart button applies the changes. Without it, the application keeps running the old code and the old version.
|
|
Using npm from the command line
If your account has terminal access (it depends on the account; there is the cPanel Terminal), the application screen shows, at the top, the command to enter the application’s virtual environment: a source of an activate file inside a nodevenv folder. Copy it exactly as shown. Once inside, node and npm are the ones for the version you picked:node -v
npm -v
npm install
npm run build
npm ls
| Command |
What for |
node -v |
Confirms the Node.js version you are in. |
npm install |
Installs the dependencies from package.json. |
npm ci |
Installs exactly what package-lock.json says, from scratch. The right one for repeating an installation. |
npm run build |
Runs the project’s build script, if it has one (many frameworks do). |
npm ls |
Lists the installed dependencies and flags the missing ones. |
|
Changed the Node.js version? Reinstall the dependencies. Some dependencies contain parts compiled for a specific version. If you switch version and do not run “Run NPM Install” (or npm ci) again, the application may start with odd errors or not start at all. If the application stops opening and the error is 503, go to 503 on a Node.js app.
|
|
The account has limits. A node_modules folder holds thousands of small files and can hit the account’s inode limit. See the limits nobody advertises. And do not use sudo or global installs (npm install -g): there is no root on a shared account.
|
|
The version you need is not in the list, or the install button gives an error? Tell us the domain and the message, and we will look at the server side.
Open a support ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon) See plans |