Monday, 16 September 2019

Noop Question: How to share variables or DB connection between modules

Dear hardworking helpers,So I need to share data between some separate js files. Like there is a general hard-coded list that every file should be able to access or the database connection.Right now with every request the database connection gets newly initialized. That's far from optimal but I somehow can't figure out how to share variables through modules and files.My structure: Router: ---router Views --- MyStuff App.jsThe router exports with module.exports = router And in App.js I use app.uses(router)But how du I access stuff in app.js like my DB connection.I hope you can help me, this is my first JS project ever and I come from a C++, Java python background. Sometimes I just don't understand how js works internaly.Thanks for every comment.

Submitted September 16, 2019 at 07:28PM by hennexl

No comments:

Post a Comment