in Education by
I'm using Node.JS with Express.js and I need to share a variable between modules, I have to do that because this variable is a pool of mysql connections, This pool creates 3 Mysql connections at the start of Node.js and then I would like that the other modules will use those connections without recreate other pools. Is this possible? Thanks JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
There are 2 options: make that variable a global one, for ex: global.MySQL_pool = .... This way you can access it everywhere by using MySQL_pool as the variable. pass it for each module where you need it as a function param, for ex: var MySQL_pool = ... var my_db_module = require('./db')(MySQL_pool); where db.js is: module.exports = function (pool) { // access the MySQL pool using the pool param here }

Related questions

0 votes
    I have these routes /items/:id /items /items/:id/edit ... etc I want to put the component, to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have these routes /items/:id /items /items/:id/edit ... etc I want to put the component, to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    when two operators like+,- share the same ranking the formula is calculate from right to left. is it true or false? Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    which term describes a could provider allowing more than one company to share or rent the same server? Select the correct answer from above options...
asked Dec 16, 2021 in Education by JackTerrance
0 votes
    Multiple containers running on a single machine all share the same resources such as the operating system kernel for instant boot and ... ? 1. True 2. False 3. Doesn't make sense...
asked Jun 22, 2021 in Technology by JackTerrance
0 votes
    How to share information between different build steps or stages in a Jenkins Job?...
asked Sep 14, 2021 in Technology by JackTerrance
0 votes
    How does one share data between components in Angular?...
asked Jun 30, 2021 in Technology by JackTerrance
0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    What happens when we access the same variable defined in two interfaces implemented by the same class? (a) ... Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    In the python documentation, an instance of a named_tuple is created by using the below code: Point = named_tuple(' ... of doing it? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    If super class and subclass have same variable name, which keyword should be used to use super class? ( ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    In which process, a local variable has the same name as one of the instance variables? a) Serialization ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    How many modules are there in Ansible?...
asked Jan 29, 2023 in Technology by JackTerrance
0 votes
    I would like to get a list of Python modules, which are in my Python installation (UNIX server). How can ... in your computer? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
...