NodeJS hosting with cPanel made it simple and easy to deploy nodejs applications using Setup Nodejs App tool. Basically this tutorial will cover step-by-step procedure to deploy and manage simple nodejs application. While writing this example we used NodeJS Hosting plan provided MediaStroke as it comes with Setup Nodejs App tool. In case, you don’t have you can buy suitable plan from here.
Table of Contents
- Step By Step Procedure To Deploy and Manage Simple Nodejs Applications
- Deploy Node.js Application
- Create Application
- Create or Upload package.json file
- Run NPM Install
- Manage Node.js Applications
- Start Application
- Stop Application
- Re-Start Application
- Edit Application
- Remove Application
- Application Log File
- Deploy Node.js Application
- Conclusion
Step By Step Procedure To Deploy and Manage Simple Nodejs Application
By following steps mentioned in this tutorial you can deploy and manage your Nodejs applications on NodeJS Hosting.
NodeJS Hosting Application Deployment
To deploy Nodejs application on NodeJS hosting, firstly you have to create the application. You can create application using cPanel graphical interface by selecting Setup Nodejs App under Software section of cPanel home screen.
Create Nodejs Application
Create the application using following steps:
- Log in to cPanel.
- Select Setup Nodejs App under Software section of cPanel home screen.
- Click CREATE APPLICATION to begin the application setup on the Setup Nodejs App page:
4. On the CREATE APPLICATION form, fill out the following fields:
- Node.js version : Choose your preferred version from the drop-down list. Latest version is recommended.
- Application mode : Select either Development or Production from the list. One may initially choose Development and then switch to Production.
- Application root : It is for the location of application files in the file system. To form the full path to the application files in the cPanel home directory, the value will be appended to
/home/<username>/
e.g./home/<username>/<applicationroot>
. - Application URL : It is to form a web URL of the application.
- Application startup file : The very first file that the application will process once it has been launched.
- Passenger log file : You can define the path along with the filename e.g.
/home/<username>/<applicationroot>logs/logs.log
.
5. Click CREATE after finishing the form.
6. After created successfully an application starts automatically. Click OPEN to view a test page for the application.
The message “It Works!” should appear.
You can now customize the environment using the package.json settings file and the npm package manager. Following the next two procedures you can achieve this.
Create package.json file
Create package.json file by following steps below:
- To access the File Manager, click the File Manager icon under the FILES area of cPanel.
- Select root folder of application under
/home/<username>/
in File Manager’s left-hand column. - To create a new file, click +File from Menu bar.
- Enter package.json as New File Name in the New File dialog box and then click Create New File.
- Use a right-click or secondary-click on the package.json file in the right-hand column of File Manager and select Edit. An edit dialog box appears.
- Click Edit to close the Edit dialog box and open file editor screen.
- Enter the following text into the editor screen.
- Save the file by clicking Save Changes.
- To close the editor, click Close.
Run NPM Install
Take the following actions to install npm:
- Select Setup Nodejs App in the SOFTWARE section of the cPanel homepage.
- Click the pencil icon in the Web Applications list’s Actions column to edit the application.
- To begin the NPM installation, click Run NPM Install.
- Displays a success message, once the NPM installation completes.
Manage Nodejs Applications
To manage Nodejs applications created use following procedures:
The Web Applications page shows the list of Nodejs applications.
Start Node.js Application
By following the steps listed below, you can start nodejs application that had stopped:
- Click the Start icon in the row of the stopped application and in the Actions column.
- Start icon changes to Stop icon, on completion of action.
Stop Nodejs Application
By following the steps listed below, you can stop nodejs application that has already started:
- Click the Stop icon in the row of an already-running application in the Actions column.
- Stop icon changes to Start icon, on completion of action.
Re-Start Node.js Application
By following the steps listed below, you can re-start nodejs application that has already started:
- Click the Restart icon in the row of an already-running application in the Actions column.
- An already-running application gets stopped and started again, on completion of action.
Delete Node.js Application
By following the steps listed below, you can delete nodejs application:
- Click the Bin icon in the row of an application that to be deleted in the Actions column.
- In the confirmation pop-up appeared, click AGREE to proceed with deletion or CANCEL to close it.
- An application will be deleted from the Web Applications list once the action is completed.
Edit Nodejs Application
By following the steps listed below, you can edit nodejs application:
- Click the Pencil icon in the row of an application you want to edit, in the Actions column.
- Application details will be opened in new tab for editing.
- You can modify below details of that applications:
- Nodejs version : To change the Nodejs version, pick one from a drop-down list.
- Application mode : To change the application mode, choose either Production or Development available in drop-down options.
- Application root : A physical address for the application on a server that corresponds to its URI must be mentioned in order to specify the application root.
- Application URL : Provide an HTTP/HTTPS URL link to the application.
- Application startup file : Enter the name of the application startup file as <filename>.js.
- Passenger log file : Specify the path to the log file.
- Environment variables : You can add or modify environment variable by specifying name and value to it. Also you can delete environment variable by clicking Bin icon in that row in Actions column. The confirmation pop-up appeared, click AGREE to proceed with deletion or CANCEL to close it.
- Following actions are available :
- RESTART : Click the RESTART button to restart the Nodejs app.
- STOP APP : Click the STOP APP button to stop the Nodejs app.
- Run NPM Install : To install the package(s) specified in the package.json file, click the Run NPM Install button.
- Run JS Script : When you click the Run JS Script button, the command(s) specified in the Scripts section of the package.json file will be executed. Click “Ok” after selecting the script’s name and specifying any other necessary parameters.
- Edit package.json : Click on edit to edit contents of package.json. The contents of package.json will be opened in editor in pop-up window. You can edit contents and then click the SAVE button to save it or CANCEL to cancel & close editor.
Conclusion:
This article summing up covering step-by-step procedure to deploy and manage Nodejs applications on server using cPanel with NodeJS Hosting. This article is written considering simple Nodejs applications particularly. For Nodejs applications with MySQL database refer another article here.
Leave a Reply