Now that I’ve started to learn node.js to a project of mine thus there will be a few articles on node that you will see. And of course I am not an expert on this topic or any actually thus making any amendments will be welcome to improve this post
Ok so I am using Ubuntu 12.04 LTS and I think ubuntu works for me atleast for stuff I wanted to do. So after reading many articles online, this is how I successfully installed node on my ubuntu.
First we will need to install pre-requisites or dependencies before we can touch node so run the following commands to install
Dependencies
You will need to install these dependencies first
1 2 3 |
sudo apt-get install python make sudo apt-get install g++ curl libssl-dev apache2-utils sudo apt-get install git-core |
If something goes wrong while installing any of the above then try these steps before you repeat above
1 2 3 |
sudo apt-get clean sudo apt-get update # repeat above install steps now |
Installing for current user
Change to the directory your want to install node in. For this example lets keep it simple and create a nodejs directory first as shown below
1 2 |
mkdir ~/nodejs cd ~/nodejs |
If everything went smoothly then its time to get the source from GIT so here are the required steps for that
1 2 3 4 5 |
git clone git://github.com/joyent/node.git cd node ./configure --prefix=~/nodejs make make install |
# update the environment path variable
echo ‘PATH=$PATH:$HOME/nodejs/bin’ >> $HOME/.bashrc
source ~/.bashrc
Please note that ./configure will do a check on dependencies and you will see problems in red if something went wrong.
Congratulations! Node is now installed and you are ready to rock
But just before that I would also recommend you to install node package manager (npm)
1 2 3 |
git clone git://github.com/isaacs/npm.git cd npm sudo make install |
npm is now installed. npm is a good way to install node modules.
But Lets test our node install out
Somewhere where you would like to create a new project, just create a new file called index.js (please note that this is just a test thus I am not emphasizing on where and how to do your project structure)
I just use gedit to do this
1 |
gedit index.js |
Ok inside your index.js put this code in
1 2 3 4 5 6 |
var http = require('http'); http.createServer(function (request, response) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end('<h2>This is my first node program</h2>'); }).listen(8080); console.log('Yay! node server is now running'); |
Ok now in your browser address bar either put localhost:8080 or if it is a local network then point your browser to network address of your node server generally starts with 192.168.*.* or 10.1.*.* remember to put 8080 as port number because thats the port our node server is listening to.
You will see This is my first node program printed on your browser window.
I hope this helps.
There is something that I recommend if you are new to node I recommend you to read this awesome beginners tutorial that can be found here
http://www.nodebeginner.org/
I hope that this little post may have helped you.
Leave your comments to help me improve this post
I am also trialing my new wordpress plugin called WP Errata so a couple of paragraphs above are correctable by you.
Cheers
very nice! thanks for tech me