Chapter 1: Introducing Node.js 14
Node.js follows a release schedule and adopts a Long-Term Support (LTS) policy. The release schedule is based on the Semantic Versioning (https://semver.org/) standard.
The Node.js release policy states that there are two major releases of Node.js per year, one in April and one in October. Major releases include breaking or incompatible API changes, although the Node.js project does try to minimize the number and impact of breaking changes to reduce disruption to users.
Even-numbered major releases of Node.js are promoted to LTS after 6 months. Even-numbered releases are scheduled for release in April and promoted to LTS in October. LTS releases are supported for 30 months. It is recommended to use LTS versions of Node.js for production applications. The purpose of the LTS policy is to provide stability to end users and also to provide a predictable timeline of releases so that users can appropriately manage their upgrades. All LTS versions of Node.js are given codenames, named after elements. Node.js 14 has the LTS codename Fermium.
Odd-numbered major releases are released in October and are only supported for 6 months. Odd-numbered releases are expected to be used to try out new features and test the migration path, but are not generally recommended for use in production applications.
The Node.js Release Working Group has authority over the Node.js release schedule and processes. The Node.js release schedule and policy documentation can be found at https://github.com/nodejs/release.
This chapter introduces Node.js – including instructions on how to install the runtime and access the API documentation.
This chapter will cover the following recipes:
- Installing Node.js 14 with nvm
- Accessing the Node.js API documentation
- Adopting new JavaScript syntax in Node.js 14
Technical requirements
This chapter will require access to a Terminal, a browser of your choice, and the internet.
Installing Node.js 14 with nvm
This book will be using Node.js 14 throughout, as it is the latest LTS release at the time of writing. Node.js 14 was released in April 2020, was promoted to LTS in October 2020 and will continue to be supported until April 2023. This recipe will cover how to install Node.js 14 using node version manager (nvm). At the time of writing, nvm is an incubation project of the OpenJS Foundation and provides an easy way to install and update Node.js versions.
Getting ready
You will need to have the appropriate permissions on your device to install nvm. This recipe assumes you're on a UNIX-like platform. If you're on Windows, it should be run under Windows Subsystem for Linux (WSL).
How to do it…
In this recipe, we're going to be installing Node.js 14 using nvm:
- First, we need to install nvm. nvm provides a script that handles the download and installation of nvm. Enter the following command in your Terminal to execute the nvm installation script:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
- nvm will automatically attempt to add itself to your path. Close and reopen your Terminal to ensure the changes have taken place. Then, enter the following command to list the nvm version we have installed; this will also confirm that nvm is available in our path:
$ nvm --version
0.37.0
- To install Node.js 14, we use the $ nvm install command. We can supply either the specific version we wish to install or the major version number. If we specify just the major version number, nvm will install the latest release of that major release line. Enter the following command to install the latest version of Node.js 14:
$ nvm install 14
Downloading and installing node v14.6.0...
Local cache found: ${NVM_DIR}/.cache/bin/node-v14.6.0-darwin-x64/node-v14.6.0-darwin-x64.tar.gz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v14.6.0-darwin-x64/node-v14.6.0-darwin-x64.tar.gz
Now using node v14.6.0 (npm v6.14.6)
Note that this command will install the latest version of Node.js 14, so your specific version install is likely to differ from that shown in the preceding output.
- The latest Node.js 14 version should now be installed and available in your path. You can confirm this by entering the following command:
$ node --version
v14.6.0
- nvm will also install the version of npm that is bundled with the Node.js version you have installed. Enter the following to confirm which version of npm is installed:
$ npm --version
6.14.6
- nvm makes it easy to install and switch between multiple Node.js versions. We can enter the following to install and switch to the latest Node.js 12 version:
$ nvm install 12
Downloading and installing node v12.18.3...
Local cache found: ${NVM_DIR}/.cache/bin/node-v12.18.3-darwin-x64/node-v12.18.3-darwin-x64.tar.gz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/bin/node-v12.18.3-darwin-x64/node-v12.18.3-darwin-x64.tar.gz
Now using node v12.18.3 (npm v6.14.6)
- Once we've got the versions installed, we can use the $ nvm use command to switch between them:
$ nvm use 14
Now using node v14.6.0 (npm v6.14.6)
We've installed the latest version of Node.js 14 using nvm.
How it works…
nvm is a version manager for Node.js on UNIX-like platforms and supports POSIX-compliant shells. POSIX is a set of standards for operating system co...