Create a node.js module just by giving the source code to a special require function
JavaScript
Switch branches/tags
Nothing to show
Latest commit ac93efe Feb 23, 2012 Schwartz Michaël v0.0.2
require function now need an id as argument in order to retrieve a source module later
Permalink
Failed to load latest commit information.
test
.gitignore
LICENCE
README.md
example.js
index.js
package.json

README.md

require-source

Create a module just by giving the js source code to a special require function

Installation

$ npm install require-source

Example usage

    var requireSource = require('require-source').require;

    //The requireSource function takes an id and the
    //module source code
    var logger = requireSource('logger', function() {
        var util = require('util');
        module.exports = function(log) {
            util.log(log);
        }
    });

    //should print 'hello' to the console
    logger('hello');

    //we can require the module later
    var myLogger = requireSource('logger');
    

    //We can create a module by giving its source code as a string
    //worldModule.world is equal to "world"
    var worldModule = requireSource('world', "module.exports.world='world'");
    

Running Tests

To run the test suite first invoke the following command within the repo, installing the development dependencies:

$ npm install

then run the tests:

$ npm test