Socket
Socket
Sign inDemoInstall

express-use-request

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-use-request

This is a small library for the nodejs express server, based on the async-hooks mechanism. It allows you to receive the current processed request from anywhere.


Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Install size
4.02 kB
Created
Weekly downloads
 

Readme

Source

#express-use-request

This is a small library for the nodejs express server, based on the async-hooks mechanism. It allows you to receive the current processed request from anywhere.

Installation

npm i express-use-request

API

middleware

First you need to connect middleware. It is recommended to connect it one of the first.

// index.js

let { middleware } = require('express-use-request');
let anyLib = require('./any-lib.js');

...

const app = express();

app.use(middleware);
app.get('/', (req, res) => {

    /**
     * There is no need passing req to anyMetod and to any nested deeper.
     */
    let result = anyLib.anyMetod({foo: 'bar'});
    
    res.status(200).send(result);
});

app.listen(3000);

useRequest

With the useRequest function, you can get the request to be processed anywhere. It may contain supporting information related to a specific request, which now does not need to be passed through the entire callstack.

// ./any-lib.js

const { useRequest } = require('express-use-request);

module.exports = {
    anyMethod: (params) => {
        // With the useRequest function, you can access a request from anywhere.
        let request = useRequest();
        
        ...
        
    }
};

Keywords

FAQs

Last updated on 23 Jul 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc