Skip to main content

Why Node.JS?

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?

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Node provides many more benefits than Ruby on Rails, a growing fan base, and the power of JavaScript.  If you are using PHP, ASP.NET, or something older (yikes - no Perl, please), you are behind the times.

Comments

Popular posts from this blog

Developing a lightweight WebSocket library

Late in 2016, I began development on a lightweight, isomorphic WebSocket library for Node.js called ws-wrapper .  Today, this library is stable and has been successfully used in many production apps. Why?  What about socket.io ?  In my opinion, socket.io and its dependencies are way too heavy .  Now that the year is 2018, this couldn't be more true.  Modern browsers have native WebSocket support meaning that all of the transports built into the socket.io project are just dead weight.  On the other hand, ws-wrapper and its dependencies weigh about 3 KB when minified and gzipped.  Similarly, ws-wrapper consists of about 500 lines of code; whereas, socket.io consists of thousands of lines of code.  As Dijkstra once famously said: "Simplicity is prerequisite for reliability." ws-wrapper also provides a few more features out of the box.  The API exposes a two-way, Promise-based request/response interface.  That is, clients can request data from servers just as easily as se

Computer Clocks Cause More Issues

Two nights ago, a leap second was added to system clocks running Linux, causing much-undesired havoc. On July 1st at 12:00 AM UTC, both of my Amazon EC2 instances fired an alarm indicating high CPU usage. I investigated to find that it was MySQL that was eating all of the CPU. I logged in and ran SHOW PROCESSLIST to find that no queries were running (these servers don't get hit much after business hours). I stopped MySQL, CPU utilization dropped back down to 1-3% (as normal). I restarted MySQL, and it started eating a lot of CPU again. Then, I restarted the server (shutdown -r now), and the problem went away. Both servers had the exact same problem (running Ubuntu 12.04 LTS). In my particular case, MySQL began eating CPU, even after being restarted.  It was a livelock. The only relevant item I saw in the syslog was: Jun 30 23:59:59 hostname kernel: [14152976.187987] Clock: inserting leap second 23:59:60 UTC Oh yeah... leap seconds.  Those are super important.

JavaScript Sticky Footer and Scroll Effect

This post talks about two different HTML/JavaScript effects: How to keep a page footer stuck at the bottom of the browser window. How to create a scrolling <div> without using a scroll bar OK. So... you have a website. You want a header stuck at the top of your page and the footer stuck at the bottom of your page. The stuff in the middle, you want to be able to scrollable. But, you don't want those ugly scrollbars to the right of your scrollable text. Maybe, instead, you'll have up arrows and down arrows above and below your <div>. When you mouseover the arrows, the text in the <div> will move up or down and create a scrolling effect. Suppose your page looks like this... <html> <head> <title>Test</title> </head> <body> <div style="position: relative; width: 700px; margin-left: auto; margin-right: auto;"> <div id="header">Header</div> <div id="scrollUp&q