git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install
After installing you can check the version of nodejs by using the following command
node -v
Install nodejs in Windows
Install Node js using cygwin
What is cygwin?
Cygwin is free software that provides a Unix-like environment and software tool set to users of any modern x86 32-bit and 64-bit versions of MS-Windows
First,you need cygwin to install node in windows
To do so, follow these steps:
Step-1:Install cygwin.
Step-2:Use setup.exe in the cygwin folder to install the following packages:
Step-3 :
Step-4:Open the cygwin command line with Start > Cygwin > Cygwin Bash Shell.
Then Run the below commands to download and build node.
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install
Without using cygwin to install node.
Follow the below steps to install
1)Visit nodejs.org
2)Click the “install” button to download the installer.
3)Run the installer (make sure you tell the installer to add references to your PATH system variables).
4)Reboot your PC.
5)That’s it!You Successfully installed nodejs
How To check the version of nodejs in windows
1)Press Win + R (for Run)
2)Type: CMD
3)Click OK
Then in command prompt type the following command to see the version of nodejs
node --version
Install Node.Js in MAC
If you're using the excellent homebrew package manager, you can install node with one command:
brew install node
Otherwise, follow the below steps:
1)Install Xcode.
2)Install git.
Then run the following commands:
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install
So,now installation node.js part is over.So next part is how to start node.js?
How to Start?
Simple Example for Hello Node
1)First Create one javascript file with the name of hellonode.js
2)Then enter the below code in that file
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
3)Then open the command line(for windows),Terminal(For Ubuntu) and type follwing command to execute the First Simple Node Program
Web servers are computers that deliver (serves up) Web pages. Every Web server has an IP address and possibly a domain name.
How to create a web server in Node.js?
Using HTTP library will create a server.So first using require keyword will include the Http library.
Example:
var http = require("http");
Also you need host name and port number for creating the server.So set the Host Name and port number
Example:
var host = "127.0.0.1";
var port = "1337";
Creating a server
Server protocol will listen for host and port number.So next We can add the code to handle the requests, and to deliver a response.
Using createServer function will handle a request and response.This function will comes under http library.
Example :
var server = http.createServer(function(request,response){
response.writeHead(200,{"content-type":"text/plain"});
response.end("Hello World");
});
You can set the response text by using wirteHead method.
Then using listen function listen the host and port for the server
var http = require("http");
console.log("Starting");
var host = "127.0.0.1";
var port = "1337";
var server = http.createServer(function(request,response){
console.log(request.url);
response.writeHead(200,{"content-type":"text/plain"});
response.end("Hello World");
});
server.listen(host,port,function(){
console.log("Listening " + host + ":" + port );
});
How to Run a server?
node server.js
Output for Above program
After running the program it will listen the host and port.Then in browser whenever reaches the host and port then it will receive the response
While Running It will Listening the port
Starting
Listening 127.0.0.1:1337
After reaching the port in browser the output will be
Starting
Listening 127.0.0.1:1337
Received request:/
Node.js is a runtime environment and a library for running applications written in JavaScript outside the browser.
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.
Node.js is an event based, asynchronous I/O framework that uses Google's V8 JavaScript Engine.
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
It is used for developing applications that make heavy use of the ability to run JavaScript both on the client, as well as on server side and therefore benefit from the re-usability of code and the lack of context switching.
Some of the Applications that can be written using Node.js.
Static file servers
Web Application frameworks
Messaging middle ware
Servers for HTML5 multi player games
Normally it is an event-driven I/O framework for the V8 JavaScript engine.
Event-driven I/O server-side JavaScript environment based on V8
What is V8?
V8 is Google's open source JavaScript engine.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
The basic philosophy of node.js is:
Non-blocking I/O - every I/O call must take a callback, whether it is to retrieve information from disk, network or another process. Built-in support for the most important protocols (HTTP, DNS, TLS) Low-level.
Do not remove functionality present at the POSIX layer. For example, support half-closed TCP connections. Stream everything; never force the buffering of data.
Note:
Node.js is different from client-side Javascript in that it removes certain things, like DOM manipulation, and adds support for evented I/O, processes, streams, HTTP, SSL, DNS, string and buffer processing and C/C++ addons.
What is KeyStone.Js? KeystoneJS is a powerful Node.js content management system and web app framework built on express and mongoose. Keystone makes it easy to create sophisticated web sites and apps, and comes with a beautiful auto-generated Admin UI.
KeystoneJS is the easiest way to build database-driven websites, applications and APIs in Node.js.
Features:
Express.js and MongoDB
Dynamic Routes
Database Fields
Auto-generated Admin UI
Simpler Code
Form Processing
Session Management
Email Sending
Keystone uses Mongoose, the leading ODM for node.js and MongoDB, and gives you a single place for your schema, validation rules and logic.
Keystone can configure Express for you, or you can take over and treat Keystone like any other Express middleware.
You can also easily integrate it into an existing Express app.