Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jed committed Apr 4, 2011
1 parent 2baecbf commit 60a5d73
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
# autorequire.js
# autorequire.js
Copyright (c) 2011 Jed Schmidt

a small module for auto-importing modules in node.js.

## usage

require( "./autorequire" )
require.auto( <module-name> )

## background

autorequire.js is for the terminally lazy. it turns boilerplate code like this:

http = require( 'http' );
https = require( 'https' );
url = require( 'url' );
path = require( 'path' );
util = require( 'util' );
crypto = require( 'crypto' );

into this:

http, https, url, path, util, crypto;

it does this by wrapping your module in a closure, like this:

!function( http, https, url, path, util, crypto ) {
// your original code here
}.apply( this, [ 'http', 'https', 'url', 'path', 'util', 'crypto' ].map( require ) )


basically, it attempts to load your module repeatedly, adding a new argument to the list every time a `not_defined` error is thrown. once all your symbols are there, it compiles and executes the module.

this module was born from a (fab) brainstorm, and is a prototype not really meant for serious use. that said, if you think it could be useful and would like me to `npm` it, lemme know.

0 comments on commit 60a5d73

Please sign in to comment.