I am new to pooling in node js. I am trying to start a pool connection at crud_new_op.js file and export the connection to db_crud.js and log it in the console.
I tried different ways but i always get "undefined" for the connection that i export from the pool...
db_crud.js
var express = require('express');
var app = express();
var crud = require('./routes/crud_op_new.js');
app.get('/search',(req,res)=>{
console.log(crud.connection);
});
app.listen(8044);
crud_op_new.js
var mysql = require('mysql');
var conn = require('../config/db_config.js');
var db = conn.database;
var pool = mysql.createPool({
connectionLimit : 100,
host : db.host,
user : db.user,
password : db.password,
database : db.database
});
pool.getConnection(function(err,connection){
if(!err){
exports.connection;
}
else {
console.log("Error at pool creation");
}
});
There i nothing wrong with database connection.