Skip to content

Node 15 Release

Node 15 is out, and we have some really cool changes to report on. First up is the release of npm 7! Npm 7 features npm workspaces. This allows the ability to create a mono-repo with npm alone. This is a big deal as we have had to use yarn workspaces to supplement until now.

🔗The default mode for unhandledRejection is changed to throw from warn

🔗warn (pre-15)

(node:89219) UnhandledPromiseRejectionWarning: Error: woops
    at Object.<anonymous> (/home/josh/Dev/node15/index.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:89219) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag '--unhandled-rejections=strict' (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:89219) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

🔗throw (15+)

Promise.reject(new Error("woops"));
               ^
Error: woops
    at Object.<anonymous> (/home/josh/Dev/node15/index.js:1:16)
    at Module._compile (node:internal/modules/cjs/loader:1083:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)
    at node:internal/main/run_main_module:17:47

🔗The V8 JavaScript engine has been updated to 8.6. This update includes some new language features such as:

🔗Promise.any()

const rabbit = new Promise(resolve) => setTimeout(resolve, 50, "rabbit"));
const tortoise = new Promise(resolve) => setTimeout(resolve, 300, "tortoise"));

const promises = [rabbit, tortoise];
Promise.any(promises).then(value => console.log(value));

// expected output: "rabbit"

🔗AggregateError

const promises = [
  Promise.reject("firstRejection"),
  Promise.reject("secondRejection"),
];

Promise.any(promises)
  // All promises fail
  .then((value) => console.log(value))
  .catch((error) => console.log(error.errors));

  // expected output: [ 'firstRejection', 'secondRejection' ]

🔗String.prototype.replaceAll()

const message =
  "Tommy went home and got a sandwich from the fridge and ate a sandwich";
const newMessage = message.replaceAll("yogurt", "a sandwich");
console.log(newMessage);

// expected output: 'Tommy went home and got yogurt from the fridge and ate yogurt'

🔗Logical AND assignment &&=

let a = 1;
let b = false;

a &&= 41;
console.log(a);

// expected output: 2

b &&= 41;
console.log(b);

// expected output: false

🔗Logical OR assignment ||=

const office = { code: "MATS", location: "" };

office.code ||= "LARS";
console.log(office.code);

// expected output: "MATS"

office.location ||= "San Antonio";
console.log(office.location);

// expected output: "San Antonio"

🔗Logical nullish assignment ??=

const office = { code: "MATS" };

office.code ??= "LARS";
console.log(office.code);

// expected output: "MATS"

office.location ??= "San Antonio";
console.log(office.location);

// expected output: San Antonio

🔗There is also a new format for package-lock.json and support for yarn.lock files. Finally, but not least, peer dependencies are now installed by default.

You can read more about this release on the following pages:

This Dot Labs is a modern web consultancy focused on helping companies realize their digital transformation efforts. For expert architectural guidance, training, or consulting in React, Angular, Vue, Web Components, GraphQL, Node, Bazel, or Polymer, visit thisdotlabs.com.

This Dot Media is focused on creating an inclusive and educational web for all. We keep you up to date with advancements in the modern web through events, podcasts, and free content. To learn, visit thisdot.co.

You might also like

Javascript

Getting Started with RxJS

Javascript

Testing Web Components with Cypress and TypeScript

Javascript

Web Components Integration using LitElement and TypeScript

Javascript

Navigation Lifecycle using Vaadin Router, LitElement and TypeScript