Node.js

Published date: March 4, 2024, Version: 1.12

Node.js is an open-source, server-side JavaScript runtime environment that allows developers to run JavaScript code outside of a web browser. It is built on the Chrome V8 JavaScript engine and is designed for building scalable, networked applications. Node.js has gained popularity for web development and server-side scripting, and it's commonly used to build web servers, APIs, and other networked applications. It has become an integral part of the modern web development stack.

Supported Node.JS Versions

A new full version of Node.js is released twice a year, in April and October. The even-numbered releases are designated LTS, indicating a Long-Term Support version. LTS versions receive support and bug-fixes for a longer period of time than regular releases, but otherwise are not any different from any of the other major versions.

The LTS version that is currently supported is: v18.  This version should be used wherever possible.  It is possible to continue using the previous LTS version which is currently in maintenance, which is v16.  Versions older than 16 should not be used.

Squads should plan to update the Node.js version of their applications at least once yearly, upgrading to the latest LTS version as soon as is feasible after the April release.  Squads are encouraged to move to the odd-numbered release in the fall as necessary, but this is lower priority.

The next LTS release will be v20 in April 2023.  At that time, v18 will be in maintenance.  6 months later, in September 2023, v16 will move from maintenance to end-of-life.  Squads should plan to upgrade to at least v18, and preferably v20, before September 2023.

Package managers – npm, yarn, pnpm

Standard Node.js practice requires the use of a package manager. These tools manage dependencies, run unit tests, and otherwise manage the setup of the application. They also provide a standard interface for Continuous Integration (CI) tools to hook into – if your application is using one of these tools, there will be a set of known commands that CI can use to build and test.

npm is the oldest and mostly widely used package manager.  It works adequately, but is generally slower and sometimes wastes more space than the other options.

yarn is somewhat faster and more secure than npm (especially yarn 2/3).  Yarn can handle fetch dependencies in parallel rather than sequentially.

pnpm (short for performance npm) re-envisions how dependencies are stored -- dependencies are stored in a single centralized location on the developer's machine, or on the CI machine, and each project that uses that dependency hard-links to the library.  pnpm is significantly faster than both yarn and npm, but has the least CI support.

CTC's CI tools currently only support npm, but yarn and pnm support are expected soon.

TypeScript

Writing JavaScript by hand is a pain at the best of time.  JavaScript has very loose rules as to what data can go into what variables, even looser rules for converting between those types, and trying to get the write version of JS to run in your particular environment can be a compatibility nightmare.  TypeScript, originally created by Microsoft, is an extension to JavaScript that overlays the language with type rules that help developers write more correct code faster.  TypeScript (TS) is implemented as a superscript of JS, so any JS code is also valid TS.  A TS transpiler checks the code and converts it to portable JS at package time.

It is very strongly recommended that in any project where JavaScript is employed, TypeScript is also employed.  Developers should adopt a TypeScript-first approach, where no new JS is written, and old JS code is upgraded to use TS syntax as it is updated and modified.

Unit Test – Jest

Unit testing is an integral part of the development process and should be included from Sprint 1.  We have an entire page on Unit Testing, which is definitely worth reading.   There are a vast number of test frameworks and addons for Node.JS.  If you're currently using one already and you like it, please continue to use it.  However, if you're unsure what to choose, or want to move to something that is recommended across CTC, then we recommend the following:

  • Jest, for unit testing

  • Jest includes IstanbulJS for test coverage analysis

  • Hamjest or Hamcrest for matchers