Skip to content

Instantly share code, notes, and snippets.

@Ravenstine
Created August 26, 2016 17:32
Show Gist options
  • Save Ravenstine/1c637d5f26513882a4482e128209d435 to your computer and use it in GitHub Desktop.
Save Ravenstine/1c637d5f26513882a4482e128209d435 to your computer and use it in GitHub Desktop.
A simple function to include non-module JavaScript code in a Node.js project.
var self = this;
var include = function(){
var len = Object.keys(arguments).length;
var code = '';
var i = 0;
while(i < len){
var file = arguments[i];
code += (fs.readFileSync(embeditorRoot + "/" + file + '.js', "utf8") + "\n");
i++;
}
(function(){
eval(code);
}).call(self);
}
// EXAMPLE:
// include('jquery', 'app', 'libs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment