@beardedtim/ctx
v0.0.1
Published
A way to keep shared context for the current execution context
Downloads
1
Readme
ctx
A way to keep shared context for the current execution context
API
Note:
@beardedtim/ctx
is designed to be a singleton in your application. As such, you should only ever callcreateCtx
once per context you wish to have in your application. Creating more than one will have unforeseen circumstances.
// ctx.js
const createCtx = require('@beardedtim/ctx')
module.exports = createCtx({
default: 'state'
})
// server.js
const ctx = require('./ctx')
app.use(async (req, res, next) => {
ctx.set('foo', 'bar')
await next()
}).use((req, res) => {
res.end(ctx.get('foo')) // sends 'bar'
})