Migrating an existing application from Node.js Selector to a manual installation
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
Section titled “Steps to Migrate Your Application”1. Create a New Application Directory
Section titled “1. Create a New Application Directory”-
Connect to your server via SSH.
-
Create a directory for your application:
mkdir ~/myappcd ~/myappnpm init -yYou can name the directory anything you want, not just
myapp.
2. Install Node.js and npm
Section titled “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, ordnf) to install them.
3. Copy Application Files
Section titled “3. Copy Application Files”- Log in to cPanel.
- On the Tools page → Software → Setup Node.js App, locate your existing application.
- Copy the files from the application’s root directory into the new directory you created (
~/myapp).
4. Modify Application Files
Section titled “4. Modify Application Files”-
Port Number
Section titled “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
Section titled “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
Section titled “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 pm2pm2 start app.jspm2 startuppm2 save