Skip to content

Migrating an Existing Node.js Application to Node.js Selector in cPanel

The Node.js Selector in cPanel allows you to run Node.js applications without manually configuring the server environment. If you already have a Node.js app, you can migrate it to the Node.js Selector with only minor modifications.

  • Go to Tools → Software → Setup Node.js App.
  • Click Create Application to set up a new environment.
  • Upload or copy your existing Node.js application files into the application root directory you specified when creating the app.

Some adjustments may be required for compatibility with the Node.js Selector:

    • If your app uses a hard‑coded port (e.g., 3000), change it to obtain a port dynamically.

    • Example:

      const express = require('express');
      const app = express();
      app.get('/myapp', (req, res) => res.send('Hello World!'));
      const server = app.listen(0, () => {
      console.log('App listening at http://localhost:' + server.address().port);
      });

      Using 0 instructs Node.js to assign an available port automatically.

    • Some Node.js versions in cPanel do not support import.

    • Replace import with require:

      const express = require('express');
      const path = require('path');
      const dotenv = require('dotenv');
    • Update routes to include the application URL if required.
  • Ensure your package.json file is in the application root.
  • In the Node.js Selector interface, click Run NPM Install to install dependencies.
  • Restart the application from the Node.js Selector dashboard.
  • Visit the Application URL to confirm it runs correctly.
  • Use Error Logs in cPanel to troubleshoot issues.