ES6+ Applications<\/li>\n<\/ul>\n\n\n\nNodeJS Hosting Application Deployment<\/h2>\n\n\n\n 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<\/strong> under Software<\/strong> section of cPanel home screen.<\/p>\n\n\n\n <\/figure>\n\n\n\nCreate Nodejs Application in NodeJs Hosting<\/h3>\n\n\n\n Create the application using following steps:<\/p>\n\n\n\n
\nLog in to cPanel.<\/li>\n\n\n\n Select Setup Nodejs App<\/strong> under Software<\/strong> section of cPanel home screen.<\/li>\n\n\n\nClick CREATE APPLICATION<\/strong> to begin the application setup on the Setup Nodejs App<\/strong> page: <\/li>\n<\/ol>\n\n\n\n <\/figure>\n\n\n\n\nOn the CREATE APPLICATION<\/strong> form, fill out the following fields:<\/li>\n<\/ol>\n\n\n\n\n
\n
\n
\nNode.js version :<\/strong> Choose your preferred version from the drop-down list. Latest version is recommended.<\/li>\n\n\n\nApplication mode :<\/strong> Select either Development<\/strong> or Production<\/strong> from the list. One may initially choose Development and then switch to Production.<\/li>\n\n\n\nApplication root :<\/strong> 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>\/<\/code> e.g. \/home\/<username>\/<applicationroot><\/code>.<\/li>\n\n\n\nApplication URL :<\/strong> It is to form a web URL of the application.<\/li>\n\n\n\nApplication startup file :<\/strong> The very first file that the application will process once it has been launched. Note: For ES6+ applications, use <\/strong>.cjs<\/code> as file extention (for startup file only)<\/strong><\/li>\n\n\n\nPassenger log file :<\/strong> You can define the path along with the filename e.g. \/home\/<username>\/<applicationroot>logs\/logs.log<\/code>.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n\nClick CREATE<\/strong> after finishing the form.<\/li>\n\n\n\nAfter created successfully an application starts automatically. Click OPEN<\/strong> to view a test page for the application.<\/li>\n<\/ol>\n\n\n\nThe message “It Works!” with NodeJs version should appear.<\/p>\n\n\n\n
NodeJs Hosting package.json file generation<\/h3>\n\n\n\n You can now customize the environment using the package.json settings file and the npm package manager. Now you can upload the project files to the application root including package.json file or create package.json file from scratch.<\/p>\n\n\n\n
Method A: Create package.json file from scratch<\/h4>\n\n\n\n <\/figure>\n\n\n\n\nTo access the File Manager, click the File Manager<\/strong> icon under the FILES area of cPanel.<\/li>\n\n\n\nSelect root folder of application under \/home\/<username>\/<\/code> in File Manager’s left-hand column.<\/li>\n\n\n\nTo create a new file, click +File<\/strong> from Menu bar.<\/li>\n\n\n\nEnter package.json as New File Name in the New File<\/strong> dialog box and then click Create New File<\/strong>.<\/li>\n\n\n\nUse a right-click or secondary-click on the package.json file in the right-hand column of File Manager and select Edit<\/strong>. An edit dialog box appears.<\/li>\n\n\n\nClick Edit<\/strong> to close the Edit dialog box and open file editor screen.<\/li>\n\n\n\nEnter the following package.json<\/code> file content into the editor screen.<\/li>\n\n\n\nSave the file by clicking Save Changes<\/strong>.<\/li>\n\n\n\nTo close the editor, click Close<\/strong>.<\/li>\n<\/ol>\n\n\n\npackage.json file content for commonjs applications:<\/p>\n\n\n\n
{\n \"name\": \"nodejsapp\",\n \"version\": \"1.0.0\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: not test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\":\"\"\n}<\/code><\/pre>\n\n\n\npackage.json file content for ES6+ application:<\/p>\n\n\n\n
{\n \"name\": \"nodejsapp\",\n \"version\": \"1.0.0\",\n \"main\": \"app.js\",\n \"type\": \"module\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: not test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\":\"\"\n}<\/code><\/pre>\n\n\n\nMethod B. Upload package.json file<\/h4>\n\n\n\n <\/figure>\n\n\n\n\nTo access the File Manager, click the File Manager<\/strong> icon under the FILES area of cPanel.<\/li>\n\n\n\nSelect root folder of application under \/home\/<username>\/<\/code> in File Manager’s left-hand column.<\/li>\n\n\n\nTo create a new file, click Upload<\/strong> from Menu bar.<\/li>\n\n\n\nClick on Select File button and choose package.json file to upload.<\/li>\n\n\n\n After complete message, your package.json file uploaded to the folder. You may now close the tab.<\/li>\n<\/ol>\n\n\n\nRun NPM Install<\/h3>\n\n\n\n Take the following actions to install npm:<\/p>\n\n\n\n
\nSelect Setup Nodejs App<\/strong> in the SOFTWARE<\/strong> section of the cPanel homepage.<\/li>\n\n\n\nClick the pencil icon in the Web Applications<\/strong> list’s Actions<\/strong> column to edit the application.<\/li>\n\n\n\nTo begin the NPM installation, click Run NPM Install<\/strong>.<\/li>\n<\/ol>\n\n\n\n <\/figure>\n\n\n\n\nDisplays a success message, once the NPM installation completes.<\/li>\n<\/ol>\n\n\n\n <\/figure>\n\n\n\nES6+ modules code issues handle in NodeJs hosting<\/h3>\n\n\n\n Modern applications are built with ES6 module, and as of now NodeJs hosting application does not supports ES6 modules. So we have to handle this issue with additional configuration in nodejs hosting. As you have added the .cjs <\/code>(commonjs) eg. app.cjs<\/code> file as entry file, you have to edit the file.<\/p>\n\n\n\n\nTo access the File Manager, click the File Manager<\/strong> icon under the FILES <\/strong>area of cPanel.<\/li>\n\n\n\nSelect root folder of application under \/home\/<username>\/<\/code> in File Manager’s left-hand column.<\/li>\n\n\n\nUse a right-click or secondary-click on the app.cjs<\/code> file in the right-hand column of File Manager and select Edit<\/strong>. An edit dialog box appears.<\/li>\n\n\n\nClick Edit<\/strong> to close the Edit dialog box and open file editor screen.<\/li>\n\n\n\nRemove any predefined code and add the following content into the editor screen.<\/li>\n<\/ol>\n\n\n\n(async ()=>{\n try {\n const app = await import('.\/app.js');\n if (app.default && typeof app.default.listen === 'function') {\n app.default.listen();\n }\n } catch (err){\n console.log('Failed to start ESM application:', err);\n process.exit(1);\n }\n})();<\/code><\/pre>\n\n\n\nHere, update the import<\/code> function with parameter as path to the main file of the project<\/p>\n\n\n\n\nSave the file by clicking Save Changes<\/strong>.<\/li>\n\n\n\nTo close the editor, click Close<\/strong>.<\/li>\n<\/ol>\n\n\n\nManage Nodejs Applications in NodeJs Hosting<\/h2>\n\n\n\n To manage Nodejs applications created use following procedures:<\/p>\n\n\n\n
The Web Applications<\/strong> page shows the list of Nodejs applications.<\/p>\n\n\n\n <\/figure>\n\n\n\nStart Node.js Application<\/h3>\n\n\n\n By following the steps listed below, you can start nodejs application that had stopped:<\/strong><\/p>\n\n\n\n\nClick the Start <\/strong>icon in the row of the stopped application and in the Actions<\/strong> column.<\/li>\n\n\n\nStart icon changes to Stop icon on completion of action.<\/li>\n<\/ol>\n\n\n\nStop Nodejs Application<\/h3>\n\n\n\n By following the steps listed below, you can stop nodejs application that has already started:<\/strong><\/p>\n\n\n\n\nClick the Stop <\/strong>icon in the row of an already-running application in the Actions<\/strong> column.<\/li>\n\n\n\nStop <\/strong>icon changes to Start <\/strong>icon, on completion of action.<\/li>\n<\/ol>\n\n\n\nRe-Start Node.js Application<\/h3>\n\n\n\n By following the steps listed below, you can<\/strong> re-start nodejs application that has already started:<\/strong><\/strong><\/p>\n\n\n\n\nClick the Restart <\/strong>icon in the row of an already-running application in the Actions<\/strong> column.<\/li>\n\n\n\nAn already-running application gets stopped and started again, on completion of action.<\/li>\n<\/ol>\n\n\n\nDelete Node.js Application<\/h3>\n\n\n\n By following the steps listed below, you can<\/strong> delete nodejs application:<\/strong><\/strong><\/p>\n\n\n\n\nClick the Bin icon in the row of an application that to be deleted in the Actions<\/strong> column.<\/li>\n\n\n\nIn the confirmation pop-up appeared, click AGREE<\/strong> to proceed with deletion or CANCEL<\/strong> to close it.<\/li>\n\n\n\nAn application will be deleted from the Web Applications<\/strong> list once the action is completed.<\/li>\n<\/ol>\n\n\n\nEdit Nodejs Application<\/h3>\n\n\n\n\n
By following the steps listed below, you can<\/strong> edit nodejs application:<\/strong><\/strong><\/p>\n\n\n\n\nClick the Pencil icon in the row of an application you want to edit, in the Actions<\/strong> column.<\/li>\n\n\n\nApplication details will be opened in new tab for editing.<\/li>\n<\/ol>\n\n\n\n <\/figure>\n\n\n\n\nYou can modify below details of that applications:\n\nNodejs version :<\/strong> To change the Nodejs version, pick one from a drop-down list.<\/li>\n\n\n\nApplication mode :<\/strong> To change the application mode, choose either Production or Development available in drop-down options.<\/li>\n\n\n\nApplication root :<\/strong> A physical address for the application on a server that corresponds to its URI must be mentioned in order to specify the application root.<\/li>\n\n\n\nApplication URL :<\/strong> Provide an HTTP\/HTTPS URL link to the application.<\/li>\n\n\n\nApplication startup file :<\/strong> Enter the name of the application startup file as <filename>.js.<\/li>\n\n\n\nPassenger log file :<\/strong> Specify the path to the log file.<\/li>\n\n\n\nEnvironment variables :<\/strong> 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<\/strong> to proceed with deletion or CANCEL<\/strong> to close it.<\/li>\n<\/ul>\n<\/li>\n\n\n\nFollowing actions are available :\n\nRESTART :<\/strong> Click the RESTART<\/strong> button to restart the Nodejs app.<\/li>\n\n\n\nSTOP APP :<\/strong> Click the STOP APP<\/strong> button to stop the Nodejs app.<\/li>\n\n\n\nRun NPM Install :<\/strong> To install the package(s) specified in the package.json file, click the Run NPM Install<\/strong> button.<\/li>\n\n\n\nRun JS Script :<\/strong> When you click the Run JS Script<\/strong> button, the command(s) specified in the Scripts<\/strong> section of the package.json file will be executed. Click “Ok” after selecting the script’s name and specifying any other necessary parameters.<\/li>\n\n\n\nEdit package.json :<\/strong> Click on edit<\/strong> 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<\/strong> button to save it or CANCEL<\/strong> to cancel & close editor.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\nConclusion:<\/h2>\n\n\n\n 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.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"
NodeJS hosting with cPanel made it simple and easy to deploy nodejs applications using Setup Nodejs App tool. Basically this […]<\/p>\n","protected":false},"author":176,"featured_media":1058,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74,88],"tags":[91,92,89,95,93,94],"class_list":["post-886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","category-nodejs-hosting-shared-hosting","tag-deploy-node-js-app-2","tag-manage-node-js-app","tag-nodejs-hosting","tag-nodejs-hosting-using-cpanel","tag-package-json","tag-run-npm-install"],"yoast_head":"\n
NodeJs Hosting cPanel, deploy & manage NodeJs Applications - cPanel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n