My function is like this for examle
function summ(a,b)
{
return a+b;
}
module.exports.summ = summ;
in other file:
var obj = require('./that file')
function app()
{
var s = obj.summ(7,7);
}
if i put console.log(s);
it is giving answer perfect.
My doubt is this will come all the time when request is coming frequently since i m using this kind of return in rest api ?
Or call back function is required like that result is
function summ(a,b,callback)
{
callback(a+b);
}
and
function app()
{
obj.summ(7,7,function(result){
var s = result;
}
}
As long as your summ function behaves in a synchronous manner, like it does in your example code, you don't have to use callbacks.
If you would use asynchronous functions in summ (anything I/O related, like reading a file, querying a database, opening a network connection), that would require passing a callback function because you would have to wait until the action is completed before you return the result (by calling the callback function).