requireAsync

Require any module or file and call it's functions async

Usage no npm install needed!

<script type="module">
  import requireAsync from 'https://cdn.skypack.dev/requireAsync';
</script>

README

requireAsync

Call any function on another thread.

Installing

npm install requireAsync

Usage

var requireAsync = require('requireAsync');

var someModule = requireAsync('some-module');
var someFile = requireAsync('./file.js');

The parameters for the returned function are

  • func - the function to call inside your required module or file
  • arguments - list as many arguments between this and the callback, these will be passed to the function
  • callback - the last argument must be a callback

Example usage

var requireAsync = require('requireAsync');

var bcrypt = requireAsync('bcryptjs');

bcrypt('hashSync', 'bacon', 8, function(err, salt) {
    if (err) {
        throw err;
    }
    console.log(salt);
});

Tips

  • Leave the function name blank (not null, not defined, blank) if the function is the default export.