# stack-storage

> This is storage for callstack

Latest version **2.0.1** (published 2020-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install stack-storage
pnpm add stack-storage
yarn add stack-storage
bun add stack-storage
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2020-05-30 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.0.0 |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nook Scheel |
| Maintainers | nook |
| Keywords | context, storage, callstack, async_hooks |

## Links

- npm: https://www.npmjs.com/package/stack-storage
- Repository: https://github.com/nooks/stack-storage
- Issues: https://github.com/nooks/stack-storage/issues
- npm.io page: https://npm.io/package/stack-storage

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2020-05-30
- 2.0.0 — 2018-08-01
- 1.0.0 — 2018-04-30

## README

stack-storage
=================

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/stack-storage.svg?style=flat
[npm-url]: https://npmjs.org/package/stack-storage
[travis-image]: https://img.shields.io/travis/nooks/stack-storage.svg?style=flat
[travis-url]: https://travis-ci.org/nooks/stack-storage
[codecov-image]: https://codecov.io/gh/nooks/stack-storage/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/nooks/stack-storage
[download-image]: https://img.shields.io/npm/dm/stack-storage.svg?style=flat-square
[download-url]: https://npmjs.org/package/stack-storage

an storage on `async_hooks`, hack callstack.

Mandatory use through the variable process.storage

## install

```bash
npm install stack-storage
```

## Usage

```js
const koa = require('koa')
const _ = require('lodash')
const uuid = require('uuid')
const { promisify } = require('util')
const Storage = require('stack-storage')

const sleep = promisify(setTimeout)

const app = new koa()

function log(...args) {
  const xRequestId = process.storage.get('x-request-id')

  console.log(xRequestId, ...args)
}

app.use((ctx, next) => {
  process.storage = new Storage([
    ['x-request-id', _.get(ctx.req.headers, 'x-request-id', `api:${uuid.v4()}`)],
  ])

  return next()
})

app.use(async (ctx, next) => {
  const { method, url } = ctx.request

  log('Incoming message', { method, url })

  await next()

  const { status, body } = ctx

  log('Server response', { status, body })
})

app.use(async (ctx) => {
  // Example async
  await sleep(500)

  ctx.body = 'Hello World'
})

app.listen(3000)
```

## License

[MIT](LICENSE)

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