Skip to content

Instantly share code, notes, and snippets.

@threepointone
Created April 14, 2012 07:12
Show Gist options
  • Save threepointone/2382589 to your computer and use it in GitHub Desktop.
Save threepointone/2382589 to your computer and use it in GitHub Desktop.
YUI-ey way to require node modules
// 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