Passing data around using responses isn't the way to go. In your middleware, you could set the connection string as a property of req
:
exports.getConnString = function(req, res, next) {
sql.query(..., function(err, results) {
... // get the connection string as per your code
req.connectionString = connectionString;
next(); // call the next middleware/route
});
};
Your route handler would get called next, and you can access the property there:
app.get('/connectionString/:id', connection.getConnString, function(req, res) {
console.log("The connection String is: ", req.connectionString);
res.send(req.connectionString);
});