{"id":930,"date":"2018-05-16T15:46:50","date_gmt":"2018-05-16T10:16:50","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=930"},"modified":"2019-06-17T15:38:38","modified_gmt":"2019-06-17T10:08:38","slug":"how-to-installsetup-node-js","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/","title":{"rendered":"How to install\/setup Node.js with cPanel"},"content":{"rendered":"<p>This article describes how to install the Node.js platform on managed hosting accounts .You can use Node.js to host third-party applications or you can run your own applications.<\/p>\n<p>Node.js is used for hosting diffrent apps, like Ghost blogging platform, etc. Bellow is instruction how to quickly and easily setup Node.js on your account<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#Installing_Nodejs_and_npm\" >Installing Node.js and npm<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#How_to_start_Nodejs_application\" >How to start\u00a0Node.js application<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#Method_1_Use_npm\" >Method #1: Use npm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#Method_2_Run_node_directly\" >Method #2: Run node directly<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#Stopping_a_Nodejs_application\" >Stopping a Node.js application<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-installsetup-node-js\/#Integrating_a_Nodejs_application_with_the_web_server\" >Integrating a Node.js application with the web server<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Installing_Nodejs_and_npm\"><\/span>Installing Node.js and npm<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Here several easy steps to quickly install\u00a0Node.js and npm (the Node.js package manager). To do this, follow these steps:<\/p>\n<p>1.Log in to your account using SSH (if is not enabled for your account contact our support).<\/p>\n<p>2.At the command prompt, type next commands:<\/p>\n<pre>cd ~ wget\u00a0https:\/\/nodejs.org\/dist\/v8.11.2\/node-v8.11.2-linux-x64.tar.xz<\/pre>\n<p>Command above will download v8.11.2 version, in case you need different version you can find latest here:\u00a0<a href=\"https:\/\/nodejs.org\/en\/download\/\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/nodejs.org\/en\/download\/<\/a><\/p>\n<p>3. To extract the Node.js files, type the following command:<\/p>\n<pre>tar xvf node-v8.11.2-linux-x64.tar.xz<\/pre>\n<p>4. Now we will rename folder to\u00a0<em>nodejs<\/em>\u00a0name, to do this type the following command:<\/p>\n<pre>mv node-v8.11.2-linux-x64 nodejs<\/pre>\n<p>5.Now install\u00a0<em>node<\/em>\u00a0and\u00a0<em>npm<\/em>\u00a0binaries, type the next\u00a0commands:<\/p>\n<pre>mkdir ~\/bin\r\ncp nodejs\/bin\/node ~\/bin\r\ncd ~\/bin\r\nln -s ..\/nodejs\/lib\/node_modules\/npm\/bin\/npm-cli.js npm<\/pre>\n<p>That is all, Node.js and npm are installed on your account. To verify, type the following commands:<\/p>\n<pre>node --version\r\nnpm --version<\/pre>\n<p>The\u00a0<em>~\/bin<\/em>\u00a0directory is in your path by default, which means you can run\u00a0<em>node<\/em>\u00a0and\u00a0<em>npm<\/em>\u00a0from any directory in your account.<\/p>\n<h4 id=\"Starting-a-Node.js-application\"><span class=\"ez-toc-section\" id=\"How_to_start_Nodejs_application\"><\/span>How to start\u00a0Node.js application<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Now after installing\u00a0Node.js, you are ready to run Node.js app. However, the exact steps to do this vary depending on the app\u00a0configuration.<\/p>\n<h5 id=\"Method-1.3A-Use-npm\"><span class=\"ez-toc-section\" id=\"Method_1_Use_npm\"><\/span>Method #1: Use npm<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Many third-party and \u201cproduction-ready\u201d applications (such as Ghost) use the\u00a0<em>npm<\/em>\u00a0program to start the application, as shown by the following command:<\/p>\n<pre>nohup npm start --production &amp;<\/pre>\n<div class=\"note\">The\u00a0<em>&amp;<\/em>\u00a0places the command in the background, and the\u00a0<em>nohup<\/em>\u00a0command ensures that the application continues running even if you log out of the current terminal session.<\/div>\n<p>For this method to work, there must be a valid\u00a0<em>package.json<\/em>\u00a0file for the application. The<em>\u00a0package.json<\/em>\u00a0file contains project metadata that the\u00a0<em>npm<\/em>\u00a0program reads to determine how to start the application, manage its dependencies, and more.<\/p>\n<h5 id=\"Method-2.3A-Run-node-directly\"><span class=\"ez-toc-section\" id=\"Method_2_Run_node_directly\"><\/span>Method #2: Run node directly<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>For simple apps, or for any application that does not have a\u00a0<em>package.json<\/em>\u00a0file, you can run the\u00a0<em>node<\/em>\u00a0executable directly and specify the application filename. For example:<\/p>\n<pre>nohup node my_app.js &amp;<\/pre>\n<p>However, you lose the benefits of using\u00a0<em>npm<\/em>\u00a0to manage the application.<\/p>\n<div class=\"note\">As above, the\u00a0<em>&amp;<\/em>\u00a0places the command in the background, and the\u00a0<em>nohup<\/em>\u00a0command ensures that the application continues running even if you log out of the current terminal session.<\/div>\n<h4 id=\"Stopping-a-Node.js-application\"><span class=\"ez-toc-section\" id=\"Stopping_a_Nodejs_application\"><\/span>Stopping a Node.js application<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To stop\u00a0Node.js app, just type the following command:<\/p>\n<pre>pkill node<\/pre>\n<p>Above\u00a0command will immediately stops all running Node.js apps.<\/p>\n<h4 id=\"Integrating-a-Node.js-application-with-the-web-server\"><span class=\"ez-toc-section\" id=\"Integrating_a_Nodejs_application_with_the_web_server\"><\/span>Integrating a Node.js application with the web server<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Depending on the type of Node.js application you are running, you may want to be able to access it using a web browser. To do this, you need to select an unused port for the Node.js application to listen on, and then define server rewrite rules that redirect visitors to the application. The following steps demonstrate how to do this:<\/p>\n<p>1.In a text editor, add the following lines to the\u00a0<em>.htaccess<\/em>\u00a0file in the<em>\/home\/username\/public_html<\/em>\u00a0directory,\u00a0 \u00a0 \u00a0 \u00a0 \u00a0where\u00a0<em>username<\/em>\u00a0represents your account username:<\/p>\n<pre class=\"code\">RewriteEngine On\r\nRewriteRule ^$ http:\/\/127.0.0.1:<em>XXXXX<\/em>\/ [P,L]\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule ^(.*)$ http:\/\/127.0.0.1:<em>XXXXX<\/em>\/$1 [P,L]\r\n\r\n<\/pre>\n<p>2.In both\u00a0<strong>RewriteRule<\/strong>\u00a0lines, replace\u00a0<em>XXXXX<\/em>\u00a0with the port on which your Node.js application listens.To run a Node.js application on a managed server, you must select an unused port, and the port number must be between\u00a0<strong>49152<\/strong>\u00a0and\u00a0<strong>65535<\/strong>(inclusive).<\/p>\n<div class=\"important\">3.Save the changes to the\u00a0<em>.htaccess<\/em>\u00a0file, and then exit the text editor. Visitors to your web site are redirected to the Node.js application listening on the specified port.<\/div>\n<div class=\"tip\">If your application fails to start, the port you chose may already be in use. Check the application log for error codes like\u00a0<strong>EADDRINUSE<\/strong>\u00a0that indicate the port is in use. If it is, select a different port number, update your application\u2019s configuration and the\u00a0<a href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/steps-to-redirecting-the-url-by-using-htaccess\/\"><em>.htaccess<\/em>\u00a0<\/a>file, and then try again.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to install the Node.js platform on managed hosting accounts .You can use Node.js to host third-party applications or you can run your own applications. Node.js is used for hosting diffrent apps, like Ghost blogging platform, etc. Bellow is instruction how to quickly and easily setup Node.js [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":937,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[154],"tags":[68,69],"class_list":["post-930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel-whm","tag-node-js","tag-web-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/05\/nodejs.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-f0","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=930"}],"version-history":[{"count":1,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/930\/revisions"}],"predecessor-version":[{"id":1990,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/930\/revisions\/1990"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/937"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}