Understanding Node.js

This introduction to Node.js is for those who have experience creating web sites and applications using server-based solutions such as PHP, ASP, or .NET, etc.

Moving from IIS and Apache

As someone who has implemented many server-based web solutions, from e-commerce to integrated corporate financial systems, I hope to extol the virtues of Node.js from a familiar vantage point.

What Node.js is

Node.js is an application that implements and manages a JavaScript run-time environment using Google's V8 engine, along with a library of built-in core functionality that implements much of the standard network and OS plumbing required to build web-centric applications and servers.

Node also includes the npm package manager that facilitates the use of community created functionality (in the form of modules).

What Node.js does

Node.js can do many things, but this blog focuses on using Node where we might have used IIS and Apache in the past. And as you will see, the flexibility of creating your own web servers will open the door to many intriguing new approaches.

The Node.js way

One of the most powerful aspects of Node.js is its minimalism. Even though there are thousands of modules available, the community generally fosters a "use only what you need" approach.

If I had to sum up any development wisdom I might have acquired over the years, I would say: "Less is more" - the fewer layers, functions, and lines of code, the more manageable, scalable, and malleable the final solution will be.

Of course you need layers, functions, and other organizing constructs to succeed. The trick is to not introduce any superfluous complexity, and always understand the purpose and use of each unit of abstraction (module, function, or framework.)

For those just learning Node.js, I strongly recommend starting with as few modules as possible. I often see folks start with a framework and several modules that claim to simplify things for you. While these modules often do have great value for their intended use, beginners will end up learning the framework rather than the fundamental approaches critical to succeeding with Node.js and asynchronous server programming.

JavaScript

One of Node's big selling points is JavaScript. Benefits of using JavaScript on the server side include:

  • Uses same language as the browser client
  • Supports asynchronous and object paradigms
  • Plays well with JSON
  • Many developers already know and enjoy JavaScript

A few use cases for Node.js

Here are just a few things you might use Node.js for that would be more challenging and/or less scalable with a traditional IIS/Apache server approach:

  • A scalable RESTful API server that does not need to manage client sessions or serve static file content (e.g., a back end service to an HTML5 app which manages its own state already)
  • A transaction server that brokers transactions between numerous clients (e.g., a massive multiplayer HTML5 or native app game server)
  • A centralized state management server that allows numerous clients to update and access real-time information (e.g., a low-latency in-memory data server)
  • A server that fulfills requests by consuming and aggregating other web services (e.g., a mashup service)

Felix's Convincing the boss article as some great use case examples.

Next post I answer the question, Why async?

For a full introduction and index to this blog: Node.js: One New Approach

Cheers!

comments powered by Disqus