Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Where to import pool.js file in my project file structure

I am currently working on my e-commerce project in node js, here is my project file structure-

public
    - assets
      - js/
      - css/
      - images/
views
    - index.ejs
    - login.ejs
config/
    - pool.js
router/
    - login.js
    - index.js
    - signup.js
app.js
.env   

Here is the code for the **pool.js** file:

```   
     require('dotenv').config();
     const mysql = require('mysql')
     
     // pool  connection 
     const pool = mysql.createPool({
             host     : process.env.DB_HOST,
             user     : process.env.DB_USER,
             password : process.env.DB_PASS,
             database : process.env.DB_NAME
     })
    
     pool.on('enqueue', (connection)=>{
            console.log('Enqueue Event Triggred')
     })
     pool.on('acquire', (connection)=>{
            console.log('connection acquired with threatId: ' + connection.threadId)
     })
     module.exports = pool;
```

and here is my router/login.js file:

    const express = require('express')
    const router = express.Router()
    const pool = require('../config/pool')
    const bodyParser = require('body-parser') 
    const urlencodedParser = bodyParser.urlencoded({ extended: true })

router.post('/', urlencodedParser, (req, res, next)=>{
    pool.getConnection(...)
})

My main question is where to import the pool.js file that can be accessible to the all routers file. And what if my code for the pool.js file is replaced by the pool cluster connection code, any error??

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!