local-storage-v8
This package is based on asyn_hooks which is added in node 8.1, make sure your node is >=8.1.
Install
npm install local-storage-v8 --save
Test
npm test
Usage
// import; // or requireconst Enable Disable GetStorage = ;
Considering local storage is mostly used in web applications,here is a simple example for koa2. The source code is here, you can also clone it from the repository.
// say.jsmodule{ const store = ; return storename;}// server.jsconst Koa = ;const app = ;const GetStorage = ;const say = ;const asyncHooks = ; const delay = { ; }; app ; app; // client.jslet rp = ; { forlet k = 0; k < 10; k++ rp; };
Dependency
The source code, which is written in Typescript, is less than 40 lines, and no extra package needed. This package is highly inspired by another similar package called async-local-storage in npmjs, where we need modify or get the value through set or get. Feel free to modify the source code.