Answer the question
In order to leave comments, you need to log in
How to move the connection to mongodb in node.js into a separate file?
There is a code:
const config = require('./config.json');
const url_db = config.mongodb.url;
const MongoClient = require("mongodb").MongoClient;
const mongoClient = new MongoClient(url_db, { useNewUrlParser: true });
mongoClient.connect(function(err, client){
const collection = client.db("eshopdb").collection("games_eu");
app.locals.collection = collection;
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question