Following are some of the important features that make Node.js the first choice of software architects.
- Asynchronous and Event Driven − All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.
- Single Threaded but Highly Scalable − Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
- No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.
- License − Node.js is released under the MIT license.
In this tutorial I will show how to install node.js on CentOS6/RHEL7 machine.
Install Node.js on CentOS6/RHEL7
Follow the below steps to install node.js on CentOS6/RHEL7 machine.
1. Install Required Packages
Run the below command to install all required packages.
# yum install gcc gcc-c++ wget
After installing require packages the development tools and screen package in your system using following commands.
# yum groupinstall "Development Tools" # yum install screen
2. Install Python
You will need to install Python 2.7 or above for latest version of node.js. So make sure you have installed proper Python version. You may also refer following article to install it.
3. Download Node.js
Now download the latest node.js code as shown below.
# cd /opt # wget http://nodejs.org/dist/v5.8.0/node-v5.8.0.tar.gz # tar xzf node-v5.8.0.tar.gz # cd node-v5.8.0
4. Extract and Compile Node.js
Now we have extracted source of node.js and use one of below command to compile source code. If you have install Python 3.5 alternatively use second one.
# ./configure [or] # python3.5 ./configure
./configure actually not compiles the source code, it only sets the compiler flags as per your system architecture ( 32/64bit ). now use below commands to actually compile the code. These commands may take more time to complete.
# make # make install
5. Verify Node.js Version
Run the below command to verify the node.js version.
# node --version v5.8.0
6. Configure Example Application using Express
Run the below command to install required nmp modules.
# npm -g install express supervisor express-generator
This time is to create application using express and npm using below set of commands
# express technical # cd technical # npm install # screen
The above commands will create a directory myapp and npm will install all the required modules to run your application from its software repository.
Now edit views/index.jade and add following content to show on default page.
# vim views/index.jade extends layout block content h1= title p Welcome to LookLinux World
Now restart your application using supervisor.
# supervisor ./bin/www
This application by default start on port 3000. Access your application by connecting your server on port 3000 in your browser.