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

express-use-request

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 23 Jul 2019

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