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

async-require

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

async-require

async module loader

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124
decreased by-38.92%
Maintainers
1
Weekly downloads
 
Created
Source

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');
  • async-require
    • requireAsync(module)Promise.<(module|Error)>
      • [~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.()](#module_async-require--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.)

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;
         })
    }

Keywords

FAQs

Package last updated on 20 Nov 2015

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