Answer the question
In order to leave comments, you need to log in
How to properly make a mysql module on nodejs?
Hello, please tell me why it is impossible to make a module for mysql in such a way that it is not constantly connected in files?
Module code:
module.exports = function () {
var mysql = require('mysql');
var pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'links'
});
return pool;
};
var pool = require("../engine/mysql.db.js");
pool.getConnection(function (err, connection) {
var sql = 'SELECT `original_url`,`code` FROM `links` WHERE `code`="' + req.params.code+'"';
connection.query(sql, function (error, results, fields) {
var result = JSON.stringify(results[0]);
res.render('index', {title: 'Express'});
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question