1.2.2 • Published 8 years ago

async-require v1.2.2

Weekly downloads
155
License
ISC
Repository
github
Last release
8 years ago

async-require

Build Status Coverage Status Dependency Status devDependency Status

async-require

asyncronous module loader

Example

//ironically loading async-require using syncronaous require.
var asyncRequire = require('async-require');

requireAsync(module) ⇒ Promise.<(module|Error)>

Kind: Exported function

ParamTypeDescription
modulestringthe path to the module without a .js extension

Example

//load script myModule.js
asyncRequire('myModule').then(function(module){
  //module has been exported
});

requireAsync~load - A promisified function that accepts a moduleId as an argument and returns a promise resolving in an object with a toString method such as a Buffer or a String.()

load is used by async-require to load the script. By default it load a file relative to the calling module similar to how require works when loading module not installed through npm. Since this function is public you can set a new load method.

Kind: inner method of requireAsync
Access: public
Example
load a script with request

var asyncRequire = require('async-require'),
    request = require('request'),
    Promise = require('promise'),
    //load must return a promise
    get = Promise.promisify(request.get);

    //overwrite the default load
    asyncRequire.load = function(url){
         //get the script
         return get(url).spread(function(res, body){
             //returrn only the body of the script
             return body;
         })
    }
1.2.2

8 years ago

1.2.1

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.0.52

10 years ago

0.0.51

10 years ago

0.0.50

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago