NodeJS: In Three(ish) Minutes.
This is a new format I’m considering trying, so let me know if you like it. I’m going to take a topic, probably always a technology, and explain it as concisely and clearly as possible in 3 minutes. To begin I’ll choose the focal technology of my recent article, NodeJS. So let’s begin!
NodeJS was created in 2009 by Ryan Dahl. Prior to NodeJS, Dahl had been working as a developer using Ruby on Rails. He got the base concept for NodeJS while using Flickr (an image uploading and sharing website), and he noticed that there was a progress bar, that told him the status of his image uploading. It seems almost a fickle feature now, but back in the late 00s, that kind of server-always-talking behaviour was new and rare. This was the case because back then, servers didn’t really have the ability necessary to process multiple things at once, such as uploading a file and also handling other requests from the same user, an idea known as concurrency.
Seeing this interaction between browser and server sparked something in Dahl. He realised that a web server needs to be able to process multiple things at the same time. The old method of get a request/send a response was outdated and ill fitting. I don’t know about you but that doesn’t make a tremendous amount of sense to me, so let me explain it further with a diagram:
A request comes in, in this case it’s a request to upload a file. The server accepts that request, and while it is processing that request (the thick dark line to the right) it handles other requests, before finally returning a response to the main request. This is the concept of concurrency at the root of NodeJS.
NodeJS wasn’t back then, and still isn’t, a web server by default. When you get NodeJS out of the box, it doesn’t just start a web server. Developers have to utilise either frameworks, or write the logic directly on top of NodeJS, to make it into a web server.
So why isn’t NodeJS just a web server by default, if that’s why it was invented? It’s because NodeJS was built to address an issue greater than just the problem of multiple requests to a website, it was built to address the idea of multiple requests and of processing multiple things at once. That’s part of the reason for the popularity of NodeJS, because it can do a lot more than just web servers.
NodeJS is used for the aforementioned web servers, but also as an operating system, a logging tool (to record say, http requests, or user generated behaviour in a desktop application), a general scripting language, and I have personally used it for developing neural networks and machine learning. But because it is by far most commonly used for web servers, I’m focusing on that aspect the most.
Anyway let’s jump ahead to NodeJS in 2018. It is now most commonly used for developing Backends. Backend meaning the part of the website you don’t see; all the logic that makes a website work. It is however also commonly coupled with the major Frontend frameworks, the part that you do see and interact with, to make what’s called a Full-Stack environment. These include Angular, Vue, and React, to name the most popular frameworks. I can go more into this full-stack development topic in another article.