Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including require.async with all npm packages installed. Try it out:

var requireAsync = require("require.async")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

require.async v0.1.1


Build Status


NodeJS has a synchronous require() because its module loading system is synchronous.

This works because NodeJS runs on the server which means IO calls to fetch module code will be fast (< 10 ms).

But not all module loading systems are synchronous.

Almost all module loading systems designed for the browser are asynchronous for the express purpose of working around higher IO latencies and keeping runtime sizes smaller. They do this by allowing for incremental loading of resources and in our case code bundles.

Code bundles are sets of statically linked modules that (exports = require("<id>")) each other.

One bundle can require another bundle using require.async(id, function success(exports), function error(err)). Notice how we are making an asynchronous call to fetch the next segment of the program we need to execute.

This approach of composing a program into bundles where one root bundle loads other bundles (which may load further bundles) is considered best practice and achieved in different ways by various toolchains.

All toolchains and runtimes can benefit from require.async() used by a developer (instead of require()) to indicate entry into an OPTIONAL / CONDITIONAL / RARE segment of the program. Programs written in this fashion are more portable.

The require.async method is inspired by CommonJS and supported by the PINF JavaScript Loader which can load code bundles conflict free into any modern JavaScript runtime.


require.async is a module that patches the require given to your module by the NodeJS module system.

It adds the method require.async(id, function success(exports), function error(err)) which you can use instead of require("<id>") to indicate entry into an OPTIONAL / CONDITIONAL / RARE segment of the program.

All plugin loaders for example should be using require.async to asynchronously load plugins.


npm install require.async



    "name": "test"



require.async("./package.json", function(info) {


$ node main.js
{"name": "test"}


Author: Christoph Dorn License: UNLICENSE

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free