22

I've noticed that Node.js has become very popular, and I've seen several instances of people doing small-scale projects in it.

I've also looked at pros and cons lists to get an idea of what Node.js can do, but I'm still not clear on how it differs from other, more mature server-side tech like PHP, Perl, or Ruby on Rails.

What, specifically, differentiates Node.js from the current alternatives, and why?

Saeed Neamati
  • 18,318

3 Answers3

19

There is two important things that make Node.js different to existing server-side frameworks, asynchronous events and the use of JavaScript as a programming language.

Asynchronous Events

While most of the existing server side frameworks use a synchronous architecture, Node.js uses an asynchronous architecture, which JavaScript can handle well. This means that the server reacts to events and sends events (messages) to e.g. the database. This style of programming is very different to a synchronous style, and may be hard to use with other languages. Node.js employs an asynchronous style with asynchronous IO and can scale well.

See also Event Driven Architecture

JavaScript

JavaScript is the programming language that web applications are using on the client. Using the same language on the server-side means that the developer can apply his JavaScript knowledge both on the client and the server, and use the same functions as needed.

I would recommend the presentation Introduction to Node.js with Ryan Dahl where he explains Node.js event-driven architecture in more detail.

Jonas
  • 14,887
  • 10
  • 70
  • 103
6

Its diffrent because its event-driven. This makes the server highly scalable.

In a nutshell;

Thread Model

  1. Client asks for something
  2. Server goes off and process the request
  3. Gives it back to the client
  4. Ready to process a new request

Event Model

  1. Client asks for something
  2. Server passes the request on for processing. Ready to process a new request
  3. Server handles more requests as they come in
  4. Server gives data back to the client when the request has finished processing
Tom Squires
  • 17,835
2

I've been under the impression that it's popularity was due to the use of JavaScript. Since lots of web developers know JavaScript, it is a selling point that they can now develop server-side code using the same language. This has a few advantages that I can think of:

  • Code files can be shared between server and client, preventing duplication of effort just to handle the two sides of the system.
  • Developers don't need to mentally switch between languages. (not a big deal in my opinion)
  • Architects don't need to choose multiple languages when architecting a web solution.
  • Someone who never developed server-side code can now do so without learning a different language. (Not likely to be a valuable argument, IMHO)
John Fisher
  • 1,795