Created
April 14, 2012 07:12
-
-
Save threepointone/2382589 to your computer and use it in GitHub Desktop.
YUI-ey way to require node modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// going to use _ for array flattening until this - http://yuilibrary.com/projects/yui3/ticket/2531371 is resolved. | |
var _ = require('underscore'), | |
YUI = require('yui3').YUI; | |
YUI.add('node-js', function (Y) { | |
Y.namespace('nodejs'); | |
Y.nodejs.require = function () { | |
var requires = {}, | |
modules = _.flatten(arguments); | |
Y.each(modules, function (m) { | |
requires[m] = require(m); | |
}); | |
return requires; | |
}; | |
}, '', { | |
requires: ['oop'] | |
}); | |
YUI().use('node-js', function (Y) { | |
var nodey = Y.nodejs.require('fs','path'); | |
console.log(nodey.fs.readFileSync('something.txt', 'utf8')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment