JavaScript Answers

How to export an async function in Node.js?

Spread the love

To export an async function in Node.js, we set the module.exports property.

For instance, we write

const doStuff = async () => {
  // ...

module.exports.doStuff = doStuff;

to define the doStuff function and set that as the value of the module.exports.doStuff to export it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *