# Set up a Node.js application
Source: https://docs.webgee.com/en/development/how-to-setup-a-nodejs-application-on-cpanel



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 [#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.json` in the application root.
* The **entry point** filename — commonly `app.js` or `server.js`.

## Create the application [#create-the-application]

1. In cPanel, open **Setup Node.js App** under **Software**.

2. Select **Create Application**.

3. Fill in:

   | Field                    | Value                                |
   | ------------------------ | ------------------------------------ |
   | Node.js version          | The version your app needs           |
   | Application mode         | **Production**                       |
   | Application root         | Where your files are, e.g. `nodeapp` |
   | Application URL          | The domain or subdomain to serve it  |
   | Application startup file | Your entry point                     |

4. Select **Create**.

cPanel creates a virtual environment and starts the app.

## Install dependencies [#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](/en/development/how-to-enter-the-virtual-environment-with-python-ruby-nodejs-selectors).
Running `npm` from a plain SSH session uses the wrong Node and installs to the
wrong place.

## Environment variables [#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 [#restart-after-changes]

<Callout type="warn">
  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.
</Callout>

## Check it 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 [#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](/en/performance/understanding-cloudlinux-and-lve-limits-enhancing-server-stability-and-performan).

## Related [#related]

* [Enter the virtual environment](/en/development/how-to-enter-the-virtual-environment-with-python-ruby-nodejs-selectors)
* [Connect over SSH](/en/development/connect-via-ssh)
