I have two node js file "a and b", and i want to pass parameter from from file a.js to file b.js and also return the result of b.js to a.js
You should create a function in file a.js and export it and call this function from the file b.js and pass the value in the arguments.
function myFunction(value){
//in value you will get your passes value
}
exports.myFunction = myFunction
const fileA = require('./a')
fileA.myFunction('you value')
You can do this by including one file to another, For Example in file "a.js" you can create a method that takes an argument as input and process it and then return back the result which then can be used by file "b.js". This two way communication can be handled through function call, please review the following code.
File a.js
function funcA(input)
{
console.log(">> Input Taking");
console.log(input);
var result = 1;
return result;
}
exports.funcA = funcA;
File b.js
const myFileA = require('./a');
var response = myFileA.funcA("John Doe");
console.log(response);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With