A gentle introduction to Node.js

Dominic Myers, a Senior UX Developer in Ely, provides a gentle introduction to the Node.js framework and discusses some of its capabilities.

If you have kept abreast of developments in web-development architecture, you will doubtless be aware of a general movement away from the two traditional platforms. Where once the majority of applications were built on either the Microsoft or LAMP (Linux, Apache, MySQL, Python/PHP) stacks there seems to be a gradual move towards a more eclectic approach. Leading to a richness and growth of the ecosystem, at the forefront of this move you will find Node.js.

Although it is having a huge impact on the modern web-development scene Node.js has roots in the relatively distant past. In 1995 Netscape LiveWire had the first server-side JavaScript engine allowing developers to put two types of Javascript tags within pages, one of which was to be executed by the client, the other compiled upon the server. However, Livewire did have an unfortunate inability to serve server-side JavaScript dynamically - it had to be compiled, on each change, into a LiveWire application. LiveWire’s server-side Javascript API also left a lot to be desired, especially compared to other languages available at the time.

Modern CPUs can process Javascript far faster than those available in the 1990s and the language itself has matured significantly. Added to that is Node.js’ event-driven non-blocking Input-Output Model, which means that when there is no work to be done Node.js will sleep.

Node.js is open-source and boasts of a package manager, npm, which has the largest ecosystem of open-source libraries in the world. As an aside, many developers have Node.js and npm installed not to serve content locally, but to make use of the tools available via the package manager.

Working with Node.js is simplicity itself, and the code should make sense to someone with only a rudimentary knowledge of programming. This snippet of code creates a simple server that listens on port 8080:

Node js (1)

As you can imagine, with such a wide ecosystem of packages available there are many frameworks available to simplify the task detailed above, perhaps the most popular is Express, and this snippet does the same as the Javascript above:

Node js (2)

The above is written in the more modern Javascript syntax of ES6/ES2015, as you can probably tell from the use of const rather than var, but both should be understandable, and Express represents just one of the many frameworks available.

Express makes up the E in the MEAN stack (MongoDB, Express, Angular and Node), but this should not be taken as a static stack as trends in development change quickly in the realm of Node.js with React taking some of the lustre from Angular recently and other NoSQL databases replacing MongoDB. It can be hard keeping track!

I mentioned above that Node.js is dormant until required. AWS have recognised that and have developed Lambda where Node.js invocation occurs on input - with bills for compute time consumed rather than for the provisioning of the underlying architecture. The serverless model is perhaps the most exciting use of Node.js and one that is gaining particular traction of late.

Serverless or server-based Node.js is not, arguably, where the most use of Node.js occurs. It has a huge impact on the development process itself as it facilitates the trans-compilation of other languages into Javascript as well as other processes which can streamline the development and minimise the assets required for web applications; allowing developers to use more modern languages without worrying about supporting older browsers.

I would recommend that you follow some of the links in this article to learn more about what Node.js does.

About the author

After a long career as a nurse, Dom moved into a career he thoroughly loves. You’ll find him wandering around the internet playing, learning and teaching new shiny technologies.

There are no comments on this item

Leave Comment

Post a comment

About this blog

This blog is brought to you by the members of the BCS Internet Specialist Group and allows you to harness their skills, expertise and knowledge. The internet is ubiquitous and has a major impact on our daily lives, at work, at home on the move. The associated risks and security concerns are real, but the magic and advantages of the internet are significant.

See all posts by Internet Specialist Group

Search this blog

January 2018