Async/Await nodejs support?

I can't say if async/await is supported in node8, but you could try wrapping the try/catch in a function like so:

async function callService() {
    try {
        const resp = await httpClient.get('users?limit=200');
    } catch(e) {
        console.error(`Fail !\n${e}`);
    }
}
callService()

since it should be clear which block will have async behavior. Also for this to work, httpClient.get() should return a Promise. Make sure it's so.


async/await is supported by node v8.x. However, await has to be inside async function. They always come in pair.

Update: Top level async/await is also supported in the latest nodejs: https://pprathameshmore.medium.com/top-level-await-support-in-node-js-v14-3-0-8af4f4a4d478