Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-ctx

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-ctx

express context based on async_hooks without getting lost

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
decreased by-10.86%
Maintainers
1
Weekly downloads
 
Created
Source

express-ctx

npm Travis (.org) Coverage Status

express context based on async_hooks without getting lost context

Install

npm i express-ctx

Usage

const express = require('express');
const { middleware, setValue, getValue } = require('express-ctx');
const usersRepository = require('./usersRepository'); // some your services

const app = express();

app.use(middleware); // must be set before using setValue/getValue

app.use((req, res, next) => {
  usersRepository.findOne(req.session.id).then(user => {
    setValue('user', user);
    next();
  });
});

app.use((req, res, next) => {
  const user = getValue('user');
  res.json(user);
});

Other libs

As for now such libraries as express-http-context and express-cls-hooked do not bind req and res to namespace, so there could be troubles with middlewares based on emitting events. So this lib binds.

Keywords

FAQs

Package last updated on 30 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc