Learning Center
Learning Center
  • HTML
  • CSS
  • JAVASCRIPT
  • Bootstrap
  • React
  • jQuery
  • NodeJs
  • Sql
  • MySql
  • Python
  • OpenVPN Setup
  • Log In
Coding Choice Home About Contact ☰

  1. You are here
  2. Home
  3. nodejs
  4. asynchronous_programming

Sidebar
  • Introduction
  • Getting Started
  • First Application
  • Modules in NodeJs
  • Create Web Server
  • ExpressJs
  • Databases in NodeJs
  • Asynchronous Programming
  • Building REST API
  • WebSockets
  • Deploying Application
  • Share via
    • Share via...
    • Twitter
    • LinkedIn
    • Facebook
    • Pinterest
    • Telegram
    • WhatsApp
    • Yammer
    • Reddit
    • Teams
  • Send via e-Mail
  • Print
  • Permalink

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);