Asynchronous Programming in Node.js

Using Promises

const fetchData = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve("Data fetched"), 2000);
  });
};
fetchData().then(console.log);

Using Async/Await

const fetchData = async () => {
  return "Data fetched";
};
fetchData().then(console.log);