i have written a function in file hello.js
dep1=require('dependency');
function hello(Args, callback){
modifiedData= dep1.someFunction(Args);
console.log(modifiedData);
callback(modifiedData);
}
module.exports=hello;
how would i re-use this function in other file?
h=require("./hello");
h.hello("Howdy!", function(err,args){
do something;
}
Any pointers?
That looks acceptable, although it is a bit hard to read. But when your callback has err as the first argument, make sure you send a null object as the first parameter:
callback(null, modifiedData);
When you are using module.exports, then the module itself can be called as that function. So you will reuse that function like this:
h = require("./hello");
h("Howdy!", function(err, args) {
//do smth
});
Otherwise, in order for your example to work, just delete module. and add the name (can be a different one):
exports.hello = hello;