In this article I will tell you how to install node in Ubuntu,Windows and MAC
and How to start.
Install Node.js in Ubuntu
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Above code will help you to install the latest version of the node.
using Git also can install nodejs
First install the dependencies
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
Then run the following commands
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 :
devel → openssl
devel → g++-gcc
devel → make
python → python
devel → git
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
node hello_node.js
Output for the above Program
Server running at http://127.0.0.1:8124/