I suggest you create a settings file with a db instance and other things that you need to use globally, like "singleton".
For example, I have settings.js with my redis db client:
var redis = require('redis'); exports.redis = redis.createClient(6379, '127.0.0.1');
And in the other few modules, I turn it on:
var settings = require('./settings'); setting.redis.<...>
A lot of the time, including it, I always have one instance of the db connection.
akaravashkin Apr 25 2018-12-12T00: 00Z
source share