How to call callback function in another callback function in node.js

Problem

How to call callback function in within callback function in node.js

Problem courtesy of: user2091059

Solution

callbacks are simply parameters in JS, just like others

just pass it to other functions

also notice that JS is lexical scoping

so make sure ur callback parameter in the scope or outer scope --> What is lexical scope?

Solution courtesy of: williamC

Discussion

Call back functions in node js are no different than those in javascript. This is one way you can call it.

 function someFunction(callback){

     callback(params);
 }

the call back function can be defined as any normal function.For example

function random(number){ 
        return Math.random()};

the function someFunction can now be called as

    someFunction(random);

That's it.The important thing to understand here is that node js is still javascript.So everything trick that works in javascript will work in node js.

Discussion courtesy of: Akshat Jiwan Sharma

This recipe can be found in it's original form on Stack Over Flow.