Node.js Selector is a feature that allows you to deploy Node.js applications on cPanel.
To access Node.js Selector, login to your cPanel account and scroll to SOFTWARE section and access Setup Node.js App
You can also use the Search function at the top of your cPanel account.
Once you are in click CREATE APPLICATION
In this page you will need to set the following before going further:
- Node.js version – selecting your preferred Node.js version, can be changed later on.
- Application mode – selecting Development or Production mode. Development mode can be chosen and changed to Production later on.
- Application root – the path to your application where you upload your application files (eg. /home/username/appname)
- Application URL – the URL of your application (eg. appname)
- Application startup file – the file that will be processed when launching the application. Needs to include a path to your file.
- Passenger log file – the path to your log
You can Add an Environment variable by clicking ADD VARIABLE
Here you can set the environment variable from the configuration page of each application.
Once you are ready click Create and you are done!
You can now access your .js files your application root by FTP or cPanel > File Manager
Installing NPM
If you want to install NPM, in Detected configuration files Click Run NPM Install and when it is done it will display NPM install completed successfully.
Head over to your URL path and you will see a default text “It works!” and the version number of your Node.js that you have selected.
Creating package JSON
If when you are trying to install NPM and it is advising that package.json is required to continue, follow this steps:
Go to cPanel > File Manager
You will see a folder that you created in “appname” earlier. (eg. in this case the app name is “appname”)
Enter the folder of your application and at the top of your File Manager you will see + File and click on it and a popup will appear.
Set the New File Name as package.json and make sure the path is correct. Create New File and Reload if you do not see the file in your File Manager
Once you have done so Right Click and Edit the file package.json
Once you are in the Editor, enter the following and click Save Changes and Close:
{
"name": "app",
"version": "1.0.0",
"description": "My App",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}