This article is for those of us who have heard all of the buzz about Node.JS and they need to convince their boss or their clients to make the switch. Or, perhaps... you're not quite convinced yet?
Why Node.JS?
Why Node.JS?
- Reason #1 - JavaScript is awesome. So, in case you didn't know, JavaScript is awesome. I'll let you read my other blog post for more details, but I'll also summarize for you:
- The language itself is extremely powerful. JavaScript comes packed with modern programming language features like closures, dynamic data types, first-class and higher-order functions, prototypes (not classes), lack of concurrency (more on this later), exception handling, garbage collection, and much, much more! These features help make your code better, keep you from making mistakes, and make your applications more bulletproof.
- JavaScript is widely adopted. It's the scripting language of the web. Need I say more? Almost any device with a web browser can run JavaScript code. JavaScript is not going anywhere any time soon.
- ...and so... You can always find JavaScript developers.
- Lots of libraries. Large community - and growing rapidly.
- JavaScript is fast. Surprisingly fast. Generally faster than PHP, Ruby, or Python.... sometimes several orders of magnitude faster. Thank you, Google, for the V8 JavaScript Engine.
- If you are developing web applications, your front-end and back-end code will be 100% JavaScript. No need to train staff on a new programming language, and you can more easily reuse code from the back-end on your front-end (or vice-versa). This significantly improves the maintainability of your application.
- Non-blocking I/O. In layman's terms, Node applications don't wait around for slow operations to complete. Node does not halt execution for any slow, normally-blocking operation (accessing the hard disk, reading from a database, etc.). In fact, it speeds along to do the next thing in line. When the blocking I/O operation completes, a callback is executed. This works incredibly well with JavaScript thanks to programming features like closures. Bottom line: It's incredibly natural to write blazing fast single-threaded applications that are still capable of handling thousands of concurrent connections. That's right - it's natural - meaning you have to work extra hard to make your application run slowly, not the other way around. Non-blocking I/O also means that you don't need to worry about threads - and all of the headaches that go along with them.
- Great API and lots of libraries
- I'd like to give Node the kudos it deserves for such an incredibly powerful, yet simple, API. Building modules for Node is simple.
- Node.JS now has the solid Express.JS web framework and all of the toys that go with it. Building web applications and RESTful APIs couldn't be much easier. For whatever reason, there are guys like TJ Holowaychuk who write a lot of very good open-source code for Node.JS. I want to find this TJ guy, congratulate him for his awesomeness, and then ask him if he ever sleeps. Thank you for Express.JS, Connect, and all of the awesomeness.
- Real-time, single-page web applications are easier. Socket.IO now provides a cross-browser web socket API, and it works great in Node.
- Databases? Yep. Node works with all of the popular ones - MySQL, Redis, and many others.
- Developing applications with Node.JS is free. This benefit is often overlooked. A lot of people use frameworks and proprietary technologies that cost money to use. Why?
Bad Use Cases - when to avoid using Node.JS
- CPU-heavy applications - use C or C++ instead
- Desktop applications - there is no GUI library for Node.JS yet. That's OK because no one wants to write desktop applications anymore. The web is the future.
Bottom Line
- If you're programming microprocessors or writing video encoding software, keep using C/C++.
- If you are building desktop applications, you should probably be building web applications.
- If you are building web applications, you should probably be using Node.
Comments