Setup Node.js on CentOS

Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications.

Let's get started on setting up our environment for Node.js and then setup a Sample Application. For this example we will setup Hexo Blog

Download Dependencies:

$ yum update -y
$ yum groupinstall "Development Tools" -y

Download and Install Nodejs:

$ curl --silent --location https://rpm.nodesource.com/setup | bash -
$ yum install nodejs -y

Setup Sample App: Hexo Blog:

$ cd /var/www
$ npm install hexo-cli -g
$ hexo init blog
$ cd blog

Now in our current directory we will see a packages.json for demonstration, it will look like the following:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.1.1"
  },
  "dependencies": {
    "hexo": "^3.1.1",
    "hexo-generator-archive": "^0.1.3",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.1.2",
    "hexo-renderer-ejs": "^0.1.0",
    "hexo-renderer-marked": "^0.2.6",
    "hexo-renderer-sass": "^0.2.0",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.2",
    "hexo-tag-bootstrap": "0.0.8",
    "hexo-tag-fontawesome": "^1.0.0"
  }
}

Now we will in install all packages listed in our mentioned file by doing:

$ npm install

Creating our first Post:

$ hexo new post "My first post"   

Output:
// INFO Created: /var/www/hexo/blog/source/_posts/my-first-post.md

Starting the Server:

$ hexo server

Output:
// INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.

For more information on Hexo, please see https://hexo.io/docs/