Socket
Book a DemoInstallSign in
Socket

mattisg.requirewith

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mattisg.requirewith

Wrapper to require() modules with dependency injection.

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

RequireWith

Allows you to do inject dependencies in (i.e. pass variables to) a required Node.js module.

Usage

var requireWith = require('mattisg.requirewith');
var mod = requireWith('./mymodule', {
	config: config,
	client: someVar
});

Then, the config and client variables will be available in mymodule.

Redefining require

You can even redefine require for a one-line replacement:

require = require('mattisg.requirewith');

This module calls require directly if no argument other than the module name is given, so it is perfectly safe to redefine require. Actually, unless you specify so explicitly, this will automatically be done recursively for modules required with injections.

To disable recursive redefinitions, pass false as the third argument. To summarize:

require = require('mattisg.requirewith');

var path = require('path');	// exactly the same as no redefinition

var mymod = require('./mymodule', {	// config can be used in mymodule, and mymodule does not need to redefine require to get injection capabilities
	config: config
});

var norec = requireWith('./mymodule', {	// config can be used in mymodule, but it gets only the default require
	config: config
}, false);

Installation

npm install mattisg.requirewith

Keywords

require

FAQs

Package last updated on 19 Jul 2012

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.