# node-ensure

> Async module-loading library and protocol for bundlers/loaders targeting isomorphic apps and Node.js.

Latest version **0.0.0** (published 2015-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-ensure
pnpm add node-ensure
yarn add node-ensure
bun add node-ensure
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2015-02-28 |
| First published | 2015-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Carl A. Bauer |
| Maintainers | bauerca |
| Keywords | require, ensure, dynamic, module, loader, bundler, async |

## Links

- npm: https://www.npmjs.com/package/node-ensure
- Repository: https://github.com/bauerca/node-ensure
- Issues: https://github.com/bauerca/node-ensure/issues
- npm.io page: https://npm.io/package/node-ensure

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.0 (latest) — 2015-02-28

## README

# node-ensure

A simple library that shims asynchronous module loading into Node.js to help
with building module bundlers and client-side loaders for isomorphic apps.
This library is super slim (read the source) and mainly represents an agreement
between developers and users of a particular bundler/loader.

NOTE: This module is *not* compatible with Browserify. It is for developers that
want to split their bundles for the client. For example, see
[dynapack](https://github.com/bauerca/dynapack).

*Syntax is inspired by the CommonJS
[Modules/Async/A](http://wiki.commonjs.org/wiki/Modules/Async/A) proposal.*


## Installation

```
npm install node-ensure
```

## Example

```js
var ensure = require('node-ensure');

ensure(['superagent', 'react'], function(err) {
  var request = require('superagent');
  var React = require('react');

  // Do the coolest of things.
});
```

If your bundler needs `require.ensure`, do this instead:

```js
require.ensure = require('node-ensure');

require.ensure(['superagent', 'react'], function(err) {
  var request = require('superagent');
  var React = require('react');

  // Do the coolest of things.
});
```

## Usage

The returned function takes an array of strings and a callback, in that
order (see the example above). The callback takes a single error argument, which
usually indicates a network problem or other client-side loader-specific runtime
error (it should never receive an error when used in Node.js).

Within the ensure callback, load modules with standard require calls.

## Bundlers/Loaders

This library primarily constitutes an agreement between users and developers of
module bundlers and (client-side) loaders. The users agree to the usage instructions
supplied above.

Bundlers and/or loaders must adhere to the following:

- The bundler/loader uses the package.json `"browser"` property for replacing
  server-only modules with browser-ready counterparts (a la Browserify).
- The `require` function passed to a module must have a `require.ensure`
  function.
- Each `require.ensure` must accept the same arguments as described in [Usage](#usage).
- Each `require.ensure` must not access variables via closure unless those variables
  are shared by **all** `require.ensure` functions.
- Each `require.ensure` may access properties
  on `this`. However, this assumes users have attached node-ensure to `require` via
  `require.ensure = require('node-ensure')`.

Happy loading!

# License

MIT

---
_Source: https://npm.io/package/node-ensure · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
