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

global-request-context

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

global-request-context

A middleware that enables to require request context.

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28
decreased by-45.1%
Maintainers
1
Weekly downloads
 
Created
Source

Global Request Context

A middleware that enables to require() request context.

Tired of passing the request context through functions? Need to get the current user session in that deeply nested function. Or simply coming from PHP or .NET and don't wanna do it the node.js way? This is the module for you?

But seriously why?

The easy answer is... just because you can!.

How to use

  1. Register the middleware
// server.js:express
const expressContext = require('global-request-context/lib/express-middleware');
...
app.use(expressContext);
// server.js:koa
const koaContext = require('global-request-context/lib/koa-middleware');
...
app.use(koaContext);
  1. Simply require the context in
// fancy-service.js
// this is the request context koa/express
const requestContext = require('global-request-context');

function handleRequestExpress() {
  const { req, res } = requestContext;
  res.send(req.query.input);
}

function handleRequestKoa() {
  const { request, response } = requestContext;
  response.body = request.query.input;
}
  1. Run the application with zone.js as a polyfill
# require zone.js at execution
node -r zone.js server.js

or

// require zone.js as the first thing that you require
require('zone.js');
...
// rest of your app code

Keywords

FAQs

Package last updated on 12 Oct 2017

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