Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load online js file with require in node

when I try to load a js file using require in node I get the error "Cannot find module 'http://bit.ly/ProjectRedBoard'". This is the code I am trying to execute,

var content = require("http://bit.ly/ProjectRedBoard");
content.run();

So basically am I doing something wrong or is require able to load files that are online?

Regards, Techhead55

EDIT: That link is now depreciated and the final code is as follows

var XMLHttpRequest = require("xhr2");
var xhr = new XMLHttpRequest();
xhr.onload = function (){
    eval(xhr.responseText);
};
xhr.open("get", "https://googledrive.com/host/0BxIYopGUx_PROTIyOVo3ZEYtWW8/run.js", true);
xhr.send();
like image 780
nathanhorton Avatar asked Jan 07 '14 05:01

nathanhorton


1 Answers

You could try downloading the file, then using require to include it once the download completes.

But really, if it's at all possible, you should download the file yourself so you know it's what you expect it to be. Running code from an external server always carries extra risk.

like image 137
Dan Hlavenka Avatar answered Nov 15 '22 08:11

Dan Hlavenka