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

require-like

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-like

Generates require functions that act as if they were operating in a given path.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
809K
decreased by-12.69%
Maintainers
1
Weekly downloads
 
Created
Source

require-like

Build Status

Generates require functions that act as if they were operating in a given path.

Install

npm install require-like

Usage

A require function that acts as if it was executed in './lib/bar':

var requireLike = require('require-like');
var myRequire = requireLike(__dirname + '/lib/bar.js');

var myFoo = myRequire('./foo.js');
var foo = require('./lib/foo');

require('assert').strictEqual(myFoo, foo);

API

requireLike(path, [uncached])

Returns a require function that acts as if it was operating in the given path.

Setting the uncached parameter to true returns a function that by-passes the module cache.

Implementation Details

This module works by accessing some private node APIs. You shouldn't worry about that so, since I will make sure this module does not break in the future by either patching it, or making a patch for node that makes the needed APIs public.

What to do with this

I use this library for dependency injection in unit tests. However, you could also use it to create experimental require addons yourself.

License

require-like is licensed under the MIT license.

FAQs

Package last updated on 22 Feb 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

  • 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