-
-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
I'm trying to get http context after a mysql query in express app. The context seems to be lost after executing a query:
const app = require('express')();
const httpContext = require('express-http-context');
const connection = require('mysql').createConnection({ ... });
connection.connect();
app.use(httpContext.middleware);
app.get('/', (req, res) => {
httpContext.set('foo', 'bar');
console.log(httpContext.get('foo')); // prints 'bar'
connection.query('SELECT * FROM some.table', (err, result, fields) => {
if (err) throw err;
console.log(httpContext.get('foo')); // prints undefined!
...
});
});
...
Please help
Metadata
Metadata
Assignees
Labels
No labels