6

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();
nathanhorton
  • 100
  • 1
  • 8
  • That link points to a Pastebin page, which serves up HTML. Even if `require` _could_ load external scripts, that link isn't Javascript code. – Dan Hlavenka Jan 07 '14 at 06:14
  • 1
    This is an super dangerous thing to do FYI. You are executing arbitrary code so you had better be sure that the script you are downloading isn't malicious. – loganfsmyth Jan 07 '14 at 06:25

2 Answers2

2

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.

Community
  • 1
  • 1
Dan Hlavenka
  • 3,697
  • 8
  • 42
  • 60
  • Well I don't really want to download the file because Im trying to have remote editing for code Im running on a Raspberry PI, plus I came with my own solution but thanks for the help. I used the xhr2 module to do a xmlhttprequest and then I eval the response text. My Solution: '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();' – nathanhorton Jan 07 '14 at 06:34
  • A more complicated solution: Dropbox has a fairly low-resource sync client that can run on a GUI-less Linux machine (like a Pi). You could put that on there, edit files in Dropbox, and `require` the path in your Dropbox folder on the local filesystem. – Dan Hlavenka Jan 08 '14 at 07:05
  • Also, in general, be super double extra careful when using `eval`. – Dan Hlavenka Jan 08 '14 at 07:06
  • Thanks, I'll try setting that up. – nathanhorton Jan 09 '14 at 14:58
0

require is only used to load local modules.

Morgan ARR Allen
  • 10,556
  • 3
  • 35
  • 33