skonves / express-http-context

Get and set request-scoped context anywhere
MIT License
300 stars 26 forks source link

Got undefined when using ecmascript #55

Closed alishefaee closed 2 years ago

alishefaee commented 2 years ago

when using ES6 I get undefined

// app.mjs
import httpContext from "express-http-context"
import express from 'express'

const app = express();

app.listen(5000,()=> console.log('listening'))

// Use any third party middleware that does not need access to the context here, e.g.
app.use(httpContext.middleware);
// all code from here on has access to the same context for each request

app.get('/', (req, res, next) => {
    let code = httpContext.get('status')
httpContext.set('status', 20)

    console.log('code')
    console.log(code)
    res.send('route')
})