Install and Use Node.js in cPanel Shared Hosting Environments

Introduction

Node.js is a robust runtime environment for running server side JavaScript applications. On Cyberin shared hosting, deploying Node.js apps is simple thanks to our cPanel interface, though there are a few limitations and best practices to keep in mind.

This guide will walk you through:

Prerequisites

Before you get started, make sure you have:

An active Cyberin shared hosting account with cPanel access
Your Node.js application files ready, or a plan to build one from scratch
Basic familiarity with web hosting and file management concepts

Note: Shared hosting environments don't provide root or SSH access for system wide installations. All Node.js and npm actions have to be done through cPanel or the terminal provided, if one is available.

Setting Up a Node.js Application in cPanel

Log in to cPanel.

Go to the Software section and click Node.js App.

Click Create Application.

Click Create.

Your application environment will now be set up. The system creates a virtual environment for your app, separate from other system processes.

Installing NPM Packages

To use npm packages in your application:

  1. In the Node.js App section, find your app and click Edit.

  2. Use the Run NPM Install button. This will install all dependencies listed in your package.json.

  3. If you need to add a new package:

  4. Click Restart Application after adding or updating packages.

> Tip: Always ensure your package.json is in your app’s root directory.

Managing Node.js Versions

Cyberin shared hosting typically lets you choose from several Node.js versions:

When you create or edit your application in the Node.js App section, simply pick your preferred version from the Node.js Version dropdown.

Keep in mind, changing the version will require you to restart your application.

Note: Installing custom Node.js versions isn't allowed on shared hosting. You can only use the versions provided in cPanel.

Example: Hello World NodeJs App

  1. Create Application Root

  2. Create index.js

    const http = require('http');
    const port = process.env.PORT || 3000;
    
    http.createServer((req, res) => {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello, World!');
    }).listen(port, () => {
      console.log(`Server running at port ${port}`);
    });
  3. Set Startup File: Point the cPanel Node.js app to index.js.

  4. Start the App: Use cPanel controls to start/restart the application.

  5. Test: Visit your application URL in a browser. You should see "Hello, World!"

Troubleshooting Common Issues

Application Not Starting

Check the startup file: Make sure the filename matches what’s set in cPanel.

Missing dependencies: Use NPM Install button or review your package.json. Port errors: always use process.env.PORT for the port, don’t hard code it.

NPM or Package Errors

Syntax or typo mistakes: double check your package.json and code files. Unsupported packages: some native modules that need compilation may not work on shared hosting.

Node.js Version Issues

Unsupported features: if you’re seeing syntax or runtime errors, check that your selected Node.js version supports the features you’re using.

File Upload/Permission Issues

Use File Manager: upload and edit files through the cPanel File Manager to avoid permission problems. Max file size: use FTP for files larger than 250 MB.

Application Crashes After Deployment

Check logs: use the View Logs feature in the Node.js App section to find error messages.

Restart the app: changes to code or dependencies often require a restart.

If you’ve tried these steps and your app still isn’t working, please submit a support ticket with details and error messages.

Best Practices & Tips