How to execute an array of synchronous and asynchronous functions in Node.js? Last Updated : 07 Oct, 2021 Comments Improve Suggest changes Like Article Like Report We have an array of functions, some functions will be synchronous and some will be asynchronous. We will learn how to execute all of them in sequence. Input: listOfFunctions = [ () => { console.log("Synchronous Function); }, async () => new Promise(resolve => { setTimeout(() => { resolve(true); console.log("Asynchronous Function); }, 100); }), . . . ] Approach 1: Treat all functions as asynchronous functions and execute them. Because in Javascript, even if you treat a synchronous function as asynchronous function, there is no problem. Example: index.js // this is our list of functions let listOfFunctions = [ () => { console.log("Synchronous Function Called"); }, async () => new Promise(resolve => { setTimeout(() => { console.log("Asynchronous Function Called"); resolve(true); }, 100); }) ] // this function will be responsible // for executing all functions of list let executeListOfFunctions = async(listOfFunctions) => { for(let func of listOfFunctions){ await func(); } } // calling main function executeListOfFunctions(listOfFunctions); Output: Approach 2: The Idea is same but, Implementation is easy in this approach. Example: index.js // this is our list of functions let listOfFunctions = [ () => { console.log("Synchronous Function Called"); }, async () => new Promise(resolve => { setTimeout(() => { console.log("Asynchronous Function Called"); resolve(true); }, 100); }) ] // this function will be responsible // for executing all functions of list let executeListOfFunctions = async(listOfFunctions) => { return Promise.all(listOfFunctions.map(func => func())); } // calling main function executeListOfFunctions(listOfFunctions); Output: Comment More infoAdvertise with us Next Article How to execute an array of synchronous and asynchronous functions in Node.js? P pratikraut0000 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Technical Scripter 2020 NodeJS-Questions +1 More Similar Reads What are the advantages of synchronous function over asynchronous function in Node.js ? Node.js furnishes us with an inbuilt fs (File System) module for different documents taking care of tasks like reading a record, composing a document, erasing a document, and so on. fs module can be introduced utilizing the underneath explanation: Syntax: npm introduce fs --save Note: The npm in the 5 min read How to Return an Array from Async Function in Node.js ? Asynchronous programming in Node.js is fundamental for handling operations like network requests, file I/O, and database queries without blocking the main thread. One common requirement is to perform multiple asynchronous operations and return their results as an array. This article explores how to 4 min read How to create an Asynchronous function in Javascript? JavaScript is a single-threaded and synchronous language. The code is executed in order one at a time. But Javascript may appear to be asynchronous in some situations. Example: HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title 6 min read Difference between Synchronous and Asynchronous Method of fs Module Asynchronous fs methods in Node.js do not block the event loop and handle multiple operations concurrently, improving performance while Synchronous fs methods block the event loop until the operation completes, which can lead to inefficiencies and slower performance for I/O-bound tasks. Table of Con 5 min read How to convert an asynchronous function to return a promise in JavaScript ? In this article, we will learn how to convert an asynchronous function to return a promise in JavaScript. Approach:Â You need to first declare a simple function (either a normal function or an arrow function (which is preferred)). You need to create an asynchronous function and then further you need 3 min read Like