Xervo

The Use Cases of Node.js

The Use Cases of Node.js

Node.js is a very powerful technology. It provides speed, flexibility, and more importantly it's all in JavaScript. Its also being used by a lot of people and some of the largest companies out there. Even with this pedigree, the first question I hear for those being introduced to Node.js is "what would I use Node.js for?" It's a valid question, one which we are going to answer today.

APIs

There are two constants for most developers: APIs and IPAs. Funny enough, the single greatest and most widely accepted use case for Node.js is APIs. The first thing LinkedIn built in Node.js was their mobile API, which they did specially for performance. Heck, the company StrongLoop has a an entire product called LoopBack that is 100% Node.js mobile APIs.

I recommend Sublime Text @Cogiva.

This all goes back to how Node.js handles requests. It is perfect for handling lots of small requests that might be I/O driven or require connections to external resources such as databases. It does all this for lots of requests at the same time, so it scales nicely too.

There are also many frameworks like Hapi, Express, and Restify that specialize in creating APIs in Node.js. Even without a powerful pre-built solution, it only takes a few lines of code to get an API started. Between the performance and ease of maintaining the API code-base, its not hard to agree Node.js fits this use case very well.

Real-Time Applications/Streaming

You can pick out pretty much any language or technology to build a web application, but single page, real-time applications are a different story. They require a quick, responsive server that can handle a flood of requests. As stated before, Node.js is perfect for this kind of thing, so naturally people have found it a good fit.

Frameworks like Sails.js and Meteor have actually attacked this niche and unsurprisingly they have gained quite a following. Of course these are not the only available solutions for making real-time applications super-simple in Node.js, and modules like SockJS allow you to start a little lower level, if that is how you roll.

Node.js also gives you the concept of "streams", allowing you to literally pipe requests to each other, or stream data directly to its destination. No caching, no temporary data, just stream from one place to another. The craziest part to this is you can modify the data as it streams, say, to zip a file as it streams to disk? This is often used for file uploads and simple proxies, since both use cases are really just throughputs to an endpoint.

Command Line Utilities

This is usually a surprise, but Node.js is actually excellent for creating scripts and command line tools. This is because, at its core, Node.js is really just a JavaScript interpreter with a few built in utilities for things like file system management and network communications. You literally can write a JavaScript script and have Node.js run it for you.

The best example of this is our own Modulus CLI. It is 100% Node.js and works just as well as any other command line tool. It's much simpler to create a utility like this in Node.js and provides all the features you would expect. We even wrote a blog post a while back on the subject, explaining all these points even further.

You can just as easily create a command line script. At Modulus we have a collection of scripts that do everything from update files in S3 to manage projects in our cloud. The core modules in Node.js are perfect for these scripts because they give you straightforward use for file system access, network communication, and even cryptography if you need it.

While Node.js doesn't provide a way to produce IPAs for you (yet), it does present a rich set of features that fit into a lot of use cases. Plus, many bright minds and tinkerers are always coming up with news ones. If all else fails, there is probably a module that does what you need.

What is Xervo?

Xervo makes deploying applications in the public cloud or your own data center easy. Node.js, PHP, Java, Python, Nginx, and MongoDB supported. Full Docker support included in Enterprise version. It’s free to get started.

Share This Article

comments powered by Disqus