Member preview

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!

“woman using computer sitting on black chair” by Bonnie Kittle on Unsplash

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:

I’m not great at diagrams ..

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.

It was built by Dahl and co in Javascript using a wonderful implementation of technology, in the form of Google’s V8 engine. This engine takes Javascript code, and compiles it into C++, which executes at lightning speeds. V8 does this on the fly, and compiles quickly upon execution. This is partly what gives NodeJS it’s edge when it comes to speed compared to other programming languages and frameworks.

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.

“black bunting flags” by Adi Goldstein on Unsplash

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.

NodeJS comes with a resource called NPM bundled into it. NPM allows the developer to manage packages, which are useful Javascript functions, and to add them to any NodeJS project. Using packages speeds up development and allows the developer to abstract away a lot of the nitty gritty development, allowing for faster code iterations.

So let’s summarize. NodeJS is a Javascript framework, built in Google’s V8 engine, and it was built to serve the need of processing multiple requests at once. It does this very well, and has become one of the most popular frameworks for developing websites because of it. And finally, developers can use the built-in NPM to add other Javascript frameworks and libraries, to speed up their own development. So that’s NodeJS very quickly! I hope you enjoyed.