DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

This Dot Media
This Dot Media

Posted on • Originally published at labs.thisdot.co on

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.
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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']
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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:

Josh Oppenheim is a Senior Software Engineer with Thisdot labs. You can reach out to him via twitter at @joshoppdev

Top comments (1)

Collapse
 
bias profile image
Tobias Nickel

we have 2020, and now we get String.replaceAll,...

I could give them a whole list of methods they should add to the prototypes.

for example: Number.times(cb) so we can write (5).times((i) =>{...}

Tired of sifting through your feed?

Find the content you want to see.

Change your feed algorithm by adjusting your experience level and give weights to the tags you follow.