Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
small module for autorequiring. warning: MAGIC!
JavaScript
tree: a1d952a506

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.md
autorequire.js
test.js

README.md

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;

if you want, you can even abuse otherwise useless javascript labels:

require: 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.

Something went wrong with that request. Please try again.