# global-request-context

> A middleware that enables to require request context.

Latest version **0.4.0** (published 2017-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install global-request-context
pnpm add global-request-context
yarn add global-request-context
bun add global-request-context
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2017-10-12 |
| First published | 2017-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | pulasthi1989@gmail.com |
| Maintainers | pulasthibandara |
| Keywords | express, request, context, middleware, koa |

## Links

- npm: https://www.npmjs.com/package/global-request-context
- Repository: https://github.com/pulasthibandara/global-request-context
- Homepage: https://github.com/pulasthibandara/global-request-context#readme
- Issues: https://github.com/pulasthibandara/global-request-context/issues
- npm.io page: https://npm.io/package/global-request-context

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2017-10-12
- 0.3.0 — 2017-10-12
- 0.2.0 — 2017-10-09
- 0.1.1 — 2017-10-07
- 0.1.0 — 2017-10-06

## README

# 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
```javascript
// server.js:express
const expressContext = require('global-request-context/lib/express-middleware');
...
app.use(expressContext);
```

```javascript
// server.js:koa
const koaContext = require('global-request-context/lib/koa-middleware');
...
app.use(koaContext);
```

2. Simply require the context in
```javascript
// 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;
}
```

3. Run the application with zone.js as a polyfill
```sh
# require zone.js at execution
node -r zone.js server.js
```

or

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

---
_Source: https://npm.io/package/global-request-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
