0 votes
148 views
in Node.js by (4.4k points)
What is callback hell in Node.js ?

1 Answer

0 votes
by (4.4k points)

Node.js Callback hell is a phenomenon that afflicts a JavaScript developer when he tries to execute multiple asynchronous operations one after the other.

An asynchronous function is one where some external activity must complete before a result can be processed; it is “asynchronous” in the sense that there is an unpredictable amount of time before a result becomes available. Such functions require a callback function to handle errors and process the result.

See the following example:-

getData(function(a){

    getMoreData(a, function(b){

        getMoreData(b, function(c){ 

            getMoreData(c, function(d){ 

            getMoreData(d, function(e){ 

            ...

        });

        });

        });

    });

});

There are following techniques to avoid callback hell:-

  1. Using Async.js
  2. Using Promises
  3. Using Async-Await

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...