'nodejs mariadb connection not disconnecting
hi I am using nodejs to create a rest API
but I am facing a problem
first see code
var http = require('http');
var url = require('url');
var mariadb = require('mariadb');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
var db_conn = mariadb.createPool({
host:"localhost",
user:"root",
password:"",
database:"database",
connectionLimit:1
});
db_conn.getConnection().then(db=>{
db.query("select * from array_languages").then(data => {
db.end();
res.write(JSON.stringify(data));
res.end();
});
});
}).listen(8080,"localhost");
this code is returning the data perfectly.
But every time I make a request the connection is still open despite the request is finished.
Expected Result
Normally what heppens, When ever I execute an script then after execution the MySql connection closes
I have tried to close the connection
by using conn.end()
but connection is still open
I am from PHP Background
In PHP if you request a page, after the execution all the connections will close automatically. but here I am facing something new.
How Can I close The connection after request finish ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

