Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why and when to use Node.js? [duplicate]

Possible Duplicate:
How to decide when to use Node.js?

Sorry if I'm a bit ambiguous, but I'm trying to understand the real advantages of using Node.js instead of other server-side language.

I'm a JavaScript enthusiast, so I'm probably going to play with Node.js, but I want to know if I should use it in my projects.

like image 503
gion_13 Avatar asked Apr 11 '11 06:04

gion_13


People also ask

What does clone node do?

The cloneNode() method creates a copy of a node, and returns the clone. The cloneNode() method clones all attributes and their values. Set the deep parameter to true if you also want to clone descendants (children).

When should you use Nodejs?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.

What is the advantage of using node js?

js really shines in building fast, scalable network applications, offers benefits in performance, faster development, and other perks. Today's requirements for processing and consuming real-time information are paramount, and Node. js is exceptionally fast for multi-user real-time data situations.

Which of the following method returns a duplicate of the node?

The cloneNode() method of the Node interface returns a duplicate of the node on which this method was called. Its parameter controls if the subtree contained in a node is also cloned or not. Cloning a node copies all of its attributes and their values, including intrinsic (inline) listeners.


2 Answers

It's evented asynchronous non-blocking I/O build ontop of V8.

So we have all the performance gain of V8 which is the Google JavaScript interpreter. Since the JavaScript performance race hasn't ended yet, you can expect Google to constantly update performance on V8 (for free).

We have non-blocking I/O which is simply the correct way to do I/O. This is based on an event loop and using asynchronous callbacks for your I/O.

It gives you useful tools like creating a HTTP server, creating a TCP server, handling file I/O.

It's a low level highly performant platform for doing any kind of I/O without having to write the entire thing in C from scratch. And it scales very well due to the non-blocking I/O.

So you want to use Node.js if you want to write highly scaling and efficient applications using non-blocking I/O whilst still having a high level scripting language available. If needed, you can hand optimise parts of your code by writing extensions in C.

There are plenty of OS libraries for Node.js that will give you abstractions, like Express.js and now.

You don't want to use Node.js if you want (slow) high level abstractions to do everything for you. You don't want to use Node.js if you want RAD. You don't want to use Node.js if you can't afford to trust a young platform, either due to having to write large pieces of code yourself to do things that are build into other frameworks or because you can't use Node.js, because the API isn't stable yet or it's a sub 1.0 release.

like image 136
Raynos Avatar answered Oct 14 '22 23:10

Raynos


The two most oft-quoted advantages are:

  • JavaScript is both server-side and client-side. There are fewer things to learn, less context switching, and the ability to reuse code across the two sides.
  • Uses non-blocking I/O, and Chrome's V8 engine, to provide fast, highly scalable servers.

For me though, the most interesting part is the amount of activity happening in this area. There are a lot of very interesting ideas under development for node - be sure to check out the list of Node.js modules.

like image 39
David Tang Avatar answered Oct 14 '22 22:10

David Tang