{"id":2528,"date":"2016-08-18T15:47:17","date_gmt":"2016-08-18T19:47:17","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2528"},"modified":"2017-11-24T18:08:33","modified_gmt":"2017-11-24T23:08:33","slug":"install-nodejs-run-node-applications-centos-7","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/","title":{"rendered":"How to install NodeJS and run node applications on CentOS 7"},"content":{"rendered":"<h1>How to install NodeJS and run node applications on CentOS 7<\/h1>\n<p>NodeJS is a server runtime for JavaScript. Many newer apps and services find that the asynchronous, single-process approach espoused by Node is easier to reason about and scale. While PHP still remains a popular choice for distributing commodity web apps, Node is becoming a big contender for uses more complicated than the average blog or wiki engine. Here we&#8217;ll get Node up and running on CentOS 7. We&#8217;ll also set up a simple app to demonstrate how you&#8217;d go about running any other Node-based code.<\/p>\n<h2>Getting Started<\/h2>\n<p>Confirm that you have the following before you follow this guide:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\"><b>Cloud Server<\/b><\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\"><b>Dedicated Server<\/b><\/a>) running CentOS 7.<br \/>\n\u2022 Root access to the node.<\/p>\n<p>You can run Node-based applications as root, but any compromise will give an attacker the ability to run code and perform actions that affect the entire server. For best results, each Node-based app should run under a dedicated user account.<\/p>\n<h2>Tutorial<\/h2>\n<p>Start by updating your server to ensure that it has all available security patches and bugfixes. Perform the update step regularly to keep your system secure and performant. We&#8217;ll also install packages that Node expects your server to have.<\/p>\n<p><code>yum update<br \/>\nyum install gcc-c++ make<\/code><\/p>\n<p>There are a few ways you might install the Node runtime. The first method involves using a Yum repository.<\/p>\n<p>There are a few different versions of Node. Which you install will depend upon the requirements of the code you are attempting to run, or in some instances, on your environment&#8217;s ability to upgrade and run new versions of Node.<\/p>\n<p>If you need stability above all else, and can&#8217;t easily upgrade components, stick with the Node Long-Term Support (LTS) release. This is currently V4.x. Here is how you&#8217;d enable and install Node&#8217;s LTS release via Yum:<\/p>\n<p><code>curl --silent --location https:\/\/rpm.nodesource.com\/setup_4.x | bash -<\/code><\/p>\n<p>Node V5 is a more recent version with additional features and APIs. Here is how Node V5 is installed via Yum:<\/p>\n<p><code>curl --silent --location https:\/\/rpm.nodesource.com\/setup_5.x | bash -<\/code><\/p>\n<p>Node V6 will eventually become the new LTS release. V6&#8217;s biggest feature is significant compatibility with Ecmascript 2015, new functionality that vastly improves and simplifies the JavaScript language.<\/p>\n<p><code>curl --silent --location https:\/\/rpm.nodesource.com\/setup_6.x | bash -<\/code><\/p>\n<p>Finally, V0.10 is an older version of Node required by some older apps and frameworks. In general, don&#8217;t use this repository unless you know that you need it.<\/p>\n<p><code>curl --silent --location https:\/\/rpm.nodesource.com\/setup | bash -<\/code><\/p>\n<p>If all of this seems complicated, you can just install the latest stable version of Node as shipped by CentOS. If you don&#8217;t know which version to use, try this method to get a Node runtime that will almost certainly work for you.<\/p>\n<p><code>yum install nodejs<\/code><\/p>\n<p>Another way to install Node is via the Node Version Manager. NVM can install several versions of Node concurrently, switching between them as required. Use this method only if you are familiar with Node, or if you are comfortable administering servers and installing language runtimes without package repositories.<\/p>\n<p>Start by installing NVM&#8217;s dependencies.<\/p>\n<p><code>yum groupinstall 'Development Tools'<br \/>\nyum install wget<\/code><\/p>\n<p>Next you&#8217;ll need the NVM installation script available on GitHub:<\/p>\n<p><code>cd \/root<br \/>\nwget https:\/\/raw.githubusercontent.com\/creationix\/nvm\/v0.31.2\/install.sh<br \/>\nbash install.sh<\/code><\/p>\n<p>When you&#8217;ve finished the installation, you&#8217;ll need to log out and in again so the modifications it made to your startup shell scripts take effect.<\/p>\n<p>Use NVM to list all available versions of NodeJS, then select the one you wish to install.<\/p>\n<p><code>nvm ls-remote<\/code><\/p>\n<p>You&#8217;ll see many versions. At the time of writing, the latest version of Node is 6.2.2. Use this version, or whatever the latest version NVM lists, unless you specifically need an earlier release.<\/p>\n<p><code class=\"gris\">(....)<br \/>\nv4.4.2<br \/>\nv4.4.3<br \/>\nv4.4.4<br \/>\nv4.4.5<br \/>\nv4.4.6<br \/>\nv4.4.7<br \/>\nv5.0.0<br \/>\nv5.1.0<br \/>\nv5.1.1<br \/>\nv5.2.0<br \/>\nv5.3.0<br \/>\nv5.4.0<br \/>\nv5.4.1<br \/>\nv5.5.0<br \/>\nv5.6.0<br \/>\nv5.7.0<br \/>\nv5.7.1<br \/>\nv5.8.0<br \/>\nv5.9.0<br \/>\nv5.9.1<br \/>\nv5.10.0<br \/>\nv5.10.1<br \/>\nv5.11.0<br \/>\nv5.11.1<br \/>\nv5.12.0<br \/>\nv6.0.0<br \/>\nv6.1.0<br \/>\nv6.2.0<br \/>\nv6.2.1<br \/>\nv6.2.2<\/code><\/p>\n<p>Use this command to install the version you choose to run:<\/p>\n<p><code>nvm install 6.2.2<\/code><\/p>\n<p>To ensure that the installation worked, let&#8217;s have NVM list the Node versions it has installed. You should see the version you chose earlier.<\/p>\n<p><code>nvm ls<\/code><br \/>\n<code class=\"gris\">->       v6.2.2<br \/>\ndefault -> 6.2.2 (-> v6.2.2)<br \/>\nnode -> stable (-> v6.2.2) (default)<br \/>\nstable -> 6.2 (-> v6.2.2) (default)<br \/>\niojs -> N\/A (default)<\/code><\/p>\n<p>You&#8217;ve installed a version of Node, but since NVM can install several versions at the same time, you must pick which is currently active. Here we&#8217;ll activate the release you&#8217;ve just downloaded.<\/p>\n<p><code>nvm use 6.2.2<\/code><\/p>\n<p>Now we verify that the activation worked.<\/p>\n<p><code>root@nodejs:~# node -v<br \/>\nv6.2.2<\/code><\/p>\n<p>Node is now installed. To ensure that it works, we&#8217;ll deploy a simple web server that displays a message when accessed. The application will use the popular Express web framework.<\/p>\n<p>First, create a directory that will contain the application.<\/p>\n<p><code>mkdir \/home\/nodeapp<br \/>\ncd \/home\/nodeapp<\/code><\/p>\n<p>Next, create the script that will run the server.<\/p>\n<p><code>nano nodetest.js<\/code><\/p>\n<p>The script should contain this code:<\/p>\n<p><code>!\/usr\/bin\/env node<br \/>\nvar express = require('express');<br \/>\nvar app = express();<br \/>\napp.get('\/', function (req, res) {<br \/>\n  res.send('Globo.Tech says Hello!');<br \/>\n});<br \/>\napp.listen(6915, function () {<br \/>\n  console.log('Basic NodeJS app listening on port 6915.');<br \/>\n});<\/code><\/p>\n<p>Save and exit. Next we need to install the Express framework so your script can use it.<\/p>\n<p><code>npm install express<\/code><\/p>\n<p>Run the script you&#8217;ve just created.<\/p>\n<p><code>node \/home\/nodeapp\/nodetest.js<\/code><\/p>\n<p>You&#8217;ll see a message on the console confirming that the server is listening for incoming connections.<\/p>\n<p><code>node nodetest.js<br \/>\nBasic NodeJS app listening on port 6915.<\/code><\/p>\n<p><code class=\"rouge\">Given that we have setup an environment path in the beginning of our script, we can make it executable to run it without specifying \"node\" in front of the script.<br \/>\nchmod +x \/rhome\/nodeapp\/nodetest.js<br \/>\n.\/nodetest.js<\/code><\/p>\n<p>Visit the URL for the server you just created. If you see the message &#8220;Globo.Tech says Hello!&#8221; in your browser, your Node stack is correctly set up!<\/p>\n<h2>Conclusion<\/h2>\n<p>You can now run any number of modern Node apps on this server. Share this article with anyone who might be looking for a great platform on which to develop modern, internet-facing services.<\/p>\n<p>If found this guide helpful, please be sure to share it with friends. You can also take a look at our other guides where we cover topics such as networking, databases, and server applications.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to install NodeJS and run node applications on CentOS 7 NodeJS is a server runtime for JavaScript. Many newer apps and services find that the asynchronous, single-process approach espoused by Node is easier to reason about and scale. While PHP still remains a popular choice for distributing commodity web apps, Node is becoming a<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[],"class_list":["post-2528","post","type-post","status-publish","format-standard","hentry","category-applications","operating_system-centos-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to install NodeJS and run node applications on CentOS 7 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now &amp; Launch your own app.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to install NodeJS and run node applications on CentOS 7 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now &amp; Launch your own app.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-18T19:47:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-24T23:08:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/\",\"name\":\"How to install NodeJS and run node applications on CentOS 7 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-08-18T19:47:17+00:00\",\"dateModified\":\"2017-11-24T23:08:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now & Launch your own app.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to install NodeJS and run node applications on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to install NodeJS and run node applications on CentOS 7 - Globo.Tech","description":"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now & Launch your own app.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How to install NodeJS and run node applications on CentOS 7 - Globo.Tech","og_description":"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now & Launch your own app.","og_url":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/","og_site_name":"Globo.Tech","article_published_time":"2016-08-18T19:47:17+00:00","article_modified_time":"2017-11-24T23:08:33+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/","url":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/","name":"How to install NodeJS and run node applications on CentOS 7 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-08-18T19:47:17+00:00","dateModified":"2017-11-24T23:08:33+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to install NodeJS and run node applications on your CentOS 7 server. Read now & Launch your own app.","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/install-nodejs-run-node-applications-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to install NodeJS and run node applications on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2528"}],"version-history":[{"count":5,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2528\/revisions"}],"predecessor-version":[{"id":3904,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2528\/revisions\/3904"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}