Node v14.3.0 released. Bye Deno?

Robert - Sep 30 '20 - - Dev Community

One of the most epic releases lately. Top-Level Await and named imports from CJS modules are now supported in v14.3.0.

Like Deno, it’s now possible to use the await keyword outside of async functions.

Let’s take a look at an example.

We will fetch a random user from a API and say hello.

// hello.js
export const sayHello = (name) => `Hello, ${name}!`;
Enter fullscreen mode Exit fullscreen mode
// index.js
import axios from "axios";
import { sayHello } from "./hello.js";

const { data } = await axios.get("https://api.namefake.com/");

console.log(sayHello(data.name));
Enter fullscreen mode Exit fullscreen mode

Add the type property in your package.json file with value of module.

{
  "name": "node-14.3.0",
  "version": "0.0.0",
  "main": "index.js",
  "type": "module",
  "dependencies": {
    "axios": "^0.20.0"
  }
}
Enter fullscreen mode Exit fullscreen mode

Run it with the --harmony-top-level-await flag.

node --harmony-top-level-await index.js
Enter fullscreen mode Exit fullscreen mode

Output:

Hello, Miss Mellie Mosciski!
Enter fullscreen mode Exit fullscreen mode

When Node finally supports remote imports, then it's a nail in the coffin for Deno.

Cover photo by @cookiethepom on Unsplash

. . . . . . . . . . . . . . . . . . .
Terabox Video Player