# embedder

> A simple tool to combine several node modules into a single script.

Latest version **0.0.2** (published 2012-03-27) · 0 weekly downloads

## Install

```sh
npm install embedder
pnpm add embedder
yarn add embedder
bun add embedder
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2012-03-27 |
| First published | 2012-02-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ~0.6.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Tim Caswell |
| Maintainers | creationix |

## Links

- npm: https://www.npmjs.com/package/embedder
- Repository: https://github.com/creationix/embedder
- npm.io page: https://npm.io/package/embedder

## Recent versions

- 0.0.2 (latest) — 2012-03-27
- 0.0.1 — 2012-02-21

## README

This is a simple tool that takes several node modules and combines them into a single file.

This is done by implementing a mini require/define system.

## Sample Usage

The best way to explain this is to show a sample usage.  Suppose that I have a node script (with dependencies) that I want to run in some node sandbox.  I can embed my script and all it's dependencies into a single script and then run that.

``` javascript
var embedder = require('embedder');
var runInNewContext = require('vm').runInNewContext;

embedder({
  // Embed my direct dependency
  "protocol": require.resolve("protocol"),
  // And also it's dependency
  "msgpack-js": require.resolve("msgpack-js"),
  // And my main script
  "client": "./node_modules/client.js",
}, function (err, code) {
  if (err) throw err;
  code += "\nrequire('client');\n";
  runInNewContext(code, {
    require: require,
    process: process,
    Buffer: Buffer,
    console: console
  }, "generated.js");
});
```

Note that I included my main script as a dependency and then bootstrapped it with a manual require line.  This isn't strictly required, but I find it cleaner.

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