In some cases, you may need to migrate your Node.js application from the Node.js Selector in cPanel to a manual Node.js installation. This is common when moving from shared or reseller hosting to an unmanaged VPS or dedicated server where the Node.js Selector is not available.

 

Steps to Migrate Your Application

1. Create a New Application Directory

  1. Connect to your server via SSH.

  2. Create a directory for your application:

    mkdir ~/myapp
    cd ~/myapp
    npm init -y
    

    You can name the directory anything you want, not just myapp.

 

2. Install Node.js and npm

  • On unmanaged hosting packages, you may need to install Node.js and npm manually.

  • Use your Linux distribution’s package manager (e.g., apt, yum, or dnf) to install them.

 

3. Copy Application Files

  1. Log in to cPanel.

  2. On the Tools page → Software → Setup Node.js App, locate your existing application.

  3. Copy the files from the application’s root directory into the new directory you created (~/myapp).

 

4. Modify Application Files

  • Port Number

    • Applications created by Node.js Selector obtain port numbers dynamically.

    • For manual installations, assign a specific port number.

    • Example using Express:

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

       

  • Routes

    • Node.js Selector apps use the value specified in the Application URL field to create the root path.

    • For manual installations, / is typically the root path.

    • Adjust your routes accordingly.

 

5. Start the Application

  • Run your app manually:

    node app.js
    
  • Or use a process manager like PM2 to keep the app running:

    npm install -g pm2
    pm2 start app.js
    pm2 startup
    pm2 save
    

     

Notes

  • Manual installations give you more flexibility but require more configuration.

  • Always secure your application with a firewall and reverse proxy (e.g., Nginx).

  • Restart the app after making changes to files or dependencies.

 
Hjalp dette svar dig? 0 Kunder som kunne bruge dette svar (0 Stem)

Powered by WHMCompleteSolution