In Node.js application, I am trying to use functions inside the javascript called on main js inside require(). Say as example, I have one js file which is database connectivity file and has functions those can be used in main javascript file. I have called require() for the database js file. Now with the variable in main js file, I want to use functions inside database js files, so I can reuse the conection object created in database js. I have read about module.exports but I didnt found the clear solution on this.
Please suggest how to achieve this.
Yes you can reuse the connection object created in different file.
for ex. in your main.js file :
here I am importing db.js file which returns me a property pool, which is assigned to my local variable pool in main.js file, now I can use at as usual.
and the db.js file
This works fine.