Skip to content
Browse files

Update README.markdown

  • Loading branch information...
1 parent fe5a971 commit cdc841384da872e957cfe009ab5a9df72aedcca8 @creationix committed Feb 21, 2012
Showing with 21 additions and 19 deletions.
  1. +21 −19 README.markdown
View
40 README.markdown
@@ -6,25 +6,27 @@ This is done by implementing a mini require/define system.
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.
- var embedder = require('embedder');
- var runInNewContext = require('vm').runInNewContext;
+``` 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");
- });
+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.

0 comments on commit cdc8413

Please sign in to comment.
Something went wrong with that request. Please try again.