Skip to content
Require a module and if not exists tries to install it globally
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
_config.yml
main.js
package.json

README.md

Lazy Dependency Require

A simple package that tries to require a node.js module and if it is fail, try to install it globally;

const ldr = require('lazy-dependency-require');

// This will try require('my-package') and if not exists local or global will execute:
// npm i -g --ignore-scripts my-package
const myPackage = ldr.require('my-package', {
    args: ['--ignore-scripts'],
    stdout: console.log,
    moduleName: 'npm module name'
});

All options are not required. If moduleName is missing, will try load 'my-package'.

Ex.:

const ldr = require('lazy-dependency-require');

// This will try require('my-package') and if not exists local or global will execute:
// npm i -g my-package
const myPackage = ldr.require('my-package');

Install

npm i lazy-dependency-require --save

NOTE

Some people do not like the idea to have a global package dependency for a lot of reasons. But in some cases this could be useful. Use it for your own.

You can’t perform that action at this time.