Node.js is a widely used, event-driven JavaScript runtime for building dynamic web applications. If you're familiar with creating Node.js apps but want to host them on a shared server, you need to configure the server environment. With cPanel, you can easily set up a virtual environment within your shared hosting account to run your Node.js app.

Here's how:

  1. Log in to cPanel.
  2. Go to Software and select Setup Node.js App.
  3. Click Create Application.
  4. Fill in the Application Root field with the directory to upload your application files.
  5. Select the Application URL and startup file. If you don't specify a startup file, app.js is used by default.
  6. Fill in the remaining fields with your preferred values.
  7. Click Create.

Entering the Virtual Environment Command Line

You can log in to your server via SSH and enter your Node virtual environment if you need to perform administrative tasks from the command line. To do so:

  1. Copy the "source" command listed above your app settings.
  2. Log in to your server via SSH.
  3. Paste the "source" command into the command prompt and hit ENTER.
  4. You'll be logged into your Node virtual environment and will see a command prompt similar to [example-node-root (10)] [userna5@server-hostname example-node-root]$

Stopping and Restarting Your App

You can stop, restart, or edit your app at any time from the cPanel interface:

  1. Log in to cPanel.
  2. Go to Software and select Setup Node.js App.
  3. Select your app from the list of existing applications.
  4. Under Actions, click to stop, restart, or edit your application.

That's it! You now know how to set up a Node.js app in your cPanel.

Was this answer helpful? 38 Users Found This Useful (110 Votes)