N
N
ninja op op2021-01-09 11:43:36
Node.js
ninja op op, 2021-01-09 11:43:36

Will a new database connection be created with every import?

There are 3 files:

// database.js
const db = require("knex")({
//...connection_info
})

module.exports = db


// index.js
const db = require("./database")

// action.js
const db = require("./database")


The question is, will there be 2 connections for two files: index.js and action.js, or will they use one single connection? If two different connections are created, how can you make sure that one single connection is used?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-01-09
@kur4chyt

Once.
Nodejs caches modules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question