Set up a Node.js application
Deploy a Node.js app in cPanel — creating the application, installing dependencies, and the restart that most changes require.
Run a Node.js application on your hosting account. Applies to shared, reseller and Premium hosting with the Node.js Selector available.
Before you begin
- Your application files uploaded, outside
public_html. cPanel serves the app through a proxy, so its source should not be directly downloadable. - A
package.jsonin the application root. - The entry point filename — commonly
app.jsorserver.js.
Create the application
-
In cPanel, open Setup Node.js App under Software.
-
Select Create Application.
-
Fill in:
Field Value Node.js version The version your app needs Application mode Production Application root Where your files are, e.g. nodeappApplication URL The domain or subdomain to serve it Application startup file Your entry point -
Select Create.
cPanel creates a virtual environment and starts the app.
Install dependencies
Use the Run NPM Install button on the application page. It reads
package.json and installs into the application's own environment.
For anything more, work in the virtual environment — see
Enter the virtual environment.
Running npm from a plain SSH session uses the wrong Node and installs to the
wrong place.
Environment variables
Add them on the application page rather than committing a .env file. Anything
in your application root may be readable if the root is ever misconfigured, and
values set here are held outside it.
Restart after changes
Node.js keeps your application in memory, so editing a file changes nothing until you restart. Unlike PHP, there is no per-request reload.
Use Restart on the application page after any code change. This is the most common reason a fix appears not to have worked.
Check it worked
Visit the application URL. If it does not respond, the application page shows the status and recent log output — start there.
Common problems
- 502 Bad Gateway — the app is not running or crashed on startup. Check the log on the application page.
- The port is wrong. Bind to
process.env.PORT, not a hard-coded number. cPanel assigns the port. - Modules not found — dependencies were installed outside the virtual environment. Use Run NPM Install, or install from inside the environment.
- It works then stops — the app may be exceeding account limits. See CloudLinux and LVE limits explained.
Related
Find your error log
Where PHP and Apache errors are written, and how to read them when a page returns a blank screen or a 500.
Deploy a Node.js app from the Websites hub
Deploy a Node.js application to a domain from a Git repository, a ZIP file or an AI agent, and set its Node version, build output and environment variables.