Top-Level Await support in Node.js v14.3.0

Prathamesh More
1 min readMay 25, 2020

--

The current version of Node.js added support for Top-Level Await just like Deno.js, and other languages like C#.

Photo by Sanni Sahil on Unsplash

Now, 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 quote from API.

Installation:

Download and Install Node.js v14.3.0

Setup:

Create Node.js project using :

npm init — yes

Now install the Axios library for fetching data from API.

npm install axios --save

Now modify apackage.json file.

Take a look here, we added type as module . Because the language has not fully implemented it yet stage 3.

Code goes like this,

Running this file using node --harmony-top-level-await top-level-async-await.js .

Output:

Response from server

--

--

Prathamesh More

Passionate, Self-taught Full Stack Web Developer that loves designing and building modern websites, applications, and APIs.