Migrating an application
In most cases, Node.js applications can be migrated to Node.js Selector with only minor modifications. To do this, follow these steps:-
Log in to cPanel.
📘 Note If you do not know how to log in to your cPanel account, please see this article.
-
Create a new application using Node.js Selector.
📘 Note For information about how to create a new Node.js application using the Node.js Selector in cPanel, please see this article.
- Copy the existing Node.js application files to the application root directory.
-
Modify the script files for the Node.js Selector environment as follows:
-
Port number: If your existing application uses a hard-coded port number, you should change it to obtain a port number dynamically. The exact method to do this varies based on the application. For example, consider the following Express Node.js application code, which uses port 3000:
You can modify this code to obtain a port number dynamically as follows:The parameter 0 in the app.listen() statement instructs Node.js to obtain a port number dynamically.
-
Import directives: Some Node.js versions do not support import directives. Therefore, you should modify any import statements to use require instead. For example, consider the following statements:
These statements can be modified to work correctly as follows:
- Routes: You may have to modify the routes in your code to include the application URL. For more information, please see this article.
-
Port number: If your existing application uses a hard-coded port number, you should change it to obtain a port number dynamically. The exact method to do this varies based on the application. For example, consider the following Express Node.js application code, which uses port 3000: