close

How can I use async/await at the top level?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I use async/await at the top level? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How can I use async/await at the top level?

  1. How can I use async/await at the top level?

    can I use async/await at the top level Node –
    You can run node --experimental-repl-await while in the REPL. I'm not so sure about scripting.
    Deno –
    Deno already has it built in.

  2. How can I use async/await at the top level?

    can I use async/await at the top level Node –
    You can run node --experimental-repl-await while in the REPL. I'm not so sure about scripting.
    Deno –
    Deno already has it built in.

Method 1

You can now use top level await in Node v13.3.0

import axios from "axios";

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

run it with --harmony-top-level-await flag

node --harmony-top-level-await index.js

Method 2

Node –
You can run node --experimental-repl-await while in the REPL. I’m not so sure about scripting.

Deno –
Deno already has it built in.

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment