Monday, May 25, 2015

What is node.js


Node is
1. A set of bindingisg to v8 for non browser work: sockets, files,

etc
2. Only exposes non-blocking, ashnychrous interfaces.
3. Only one thread, one call stack ( like the browser)
4. Low level features : E.G half closed TCP connection, TCP

throttling, UDP.
5. Has killer HTTP support.

Because the interface is purely non-blocking, users tend to achieve

decent concurrency without knowing what they are doing.
Non-blocking jail.

. No Mutex locks
. only one thing at a time
. no thread safety issue.
. Almost no side effects once event is emitted.

Node architect:
Node Standered liberary -- java script
node bindingis           -- c++ -- non blocking process calls
v8|thread pool|event loop -- c

Examples:

Node is command line tool. you have to download it and install it.

No dependencies other than python for the build system. V8 is

included in the distribution.
1. setTimeout(function(){
  console.log('wprld');
},2000);

console.log('hello');

A programs which prints "hello", wait 2 sec , ouputs "worlds" and

then exist.
SO node always exist after there is no other callbacks to be

completed.When the event loop has no timeouts or file descriptors

on it, it exists automatically.

example 2.
Every 500ms print "hello"
on SIGINT print "buy"
Using the special process object.
--> In node, you have this process global variable. it's kind of

the node is very process oriented.

setInterval(function() {

console.log('hello');
},500);

Process.on('SIGINT' function() {
    console.log('bye');
process.exit(0);   --> setting a callback, we are listening for the

SIGINT event on the process object.

Like process, many other objects in Node emit events.
A TCP server emits a "connection" event each time someone conects.
A HTTP upload emits a "data" event on each packet.

Event emitting is the kind of the fundamental in the node.

Example3.
A program which:
Starts a TCP server on port 8000
Send the peer a message
Colse the connection

--> This requires a module. Require is how you load a module in

node, this is the common JS module specification. So, you load the

net module, which is how u create a TCP server and do

net.createServer, it gives you a server and then you listen to the

connection event on that object. That connection event gives you a

call back with a socket which we call c here. And all you do is you

- on that callback, you do c.end, which send the argument to the

connection and cloases the connection.

net = require("net");

s=net.createServer();

net.on('connection', function(c){
c.end('hello');
});

s.listen(8000);

14 comments:

Abiya Carol said...

Well, you don’t really have a choice. It is a physical law in the world of functional programming to start off with SICP, which is using a minimal version of Scheme.

But, I would ignore Scheme after that readIt and full understanding is complete, and go to Clojure as a real language. Reasons?

It has direct access to all of JVM and its many libraries.
It has quite good production-ready web frameworks, such as Ring.
Even though leaving lists as the canonical aggregation structure is something of heresy in the LISP world, the added structures and literal forms in Clojure is a great help when solving real problems; specifically the map (or hash…) literal form.

java training in chennai

Nandhini said...

This blog is having the general information. Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog. This is very interesting and useful.
Security Services in Chennai

Swethapriya said...



Truely a very good article on how to handle the future technology. After reading your post,thanks for taking the time to discuss this content.


Tooth Braces In Chennai

Thamarai Ravi said...

Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
SEO Company in Chennai

Thamarai Ravi said...

Excellent and very cool idea and the subject at the top of magnificence and I am happy to this post..Interesting post! Thanks for writing it.What's wrong with this kind of post exactly? It follows your previous guideline for post length as well as clarity.
Web Development Company in India

Deepika said...


This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.


Best Root Canal Treatment In Chennai

Sri akshaya said...

very interesting to read,thanks for sharing that wonderful useful information,given articles was very excellent and easily observe all provided information.


Digital Marketing Company in Chennai

Thamizharasi J said...

nice reference i got from your article keep sharing more information for us. and keep update lot of things used to develop my business growth. thanks for well info.
SAT Training Centre in Chennai
SAT Coaching Chennai

Thamizharasi J said...

Thanks for the above post.I am using gmail from so long time. Now its time to change the color and background of my account. I am trying this but I think here is some problem in doing this. Its not done like you mentioned above. I will try again and then send you feedback. Thanks once again.
SAT Training Centre in Chennai
SAT Coaching Chennai

Akshaysri said...

It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command .
best GMAT coaching classes in chennai

Akshaysri said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
Facility Management Companies in Chennai


Abiya Carol said...

It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.

Seo Training in Chennai

Shalini said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

Seo Company in Chennai

bavana princy said...


Thanks for this blog. provided great information. All the details are explained clearly with the great explanation. Thanks for this wonderful blog. Step by step processes execution are given clearly.Know the details about different thing.
Seo Company in India