0

I wish to have the contents of an entire file evaluated in node - in this case, the angular.js source file.

the code should look something like this:

jsdom = require("jsdom").jsdom;
document = jsdom("<html><head></head><body>hello world</body></html>");
window = document.parentWindow;
navigator = window.navigator;
(eval-file "angular.js")
angular = window.angular;

what would be the best way to write the eval-file function so that it blocks until angular.js is loaded and then continues

2 Answers 2

0

You can simply require it -- require("angular.js");.

3
  • I tried it and it didn't work... it gave the error 'module not found'
    – zcaudate
    Nov 17, 2013 at 11:59
  • You would need to set up anything else you need (e.g. window) before requiring the file. Nov 17, 2013 at 12:02
  • Yeah.. I did that... I replaced the last two lines of my answer with require and it did not work
    – zcaudate
    Nov 17, 2013 at 21:22
0

In the end, I did this:

jsdom = require('jsdom').jsdom;
document = jsdom('<html><head></head><body>hello world</body></html>');        
window = document.parentWindow;
navigator = window.navigator;      
fs = require('fs');
angular_file = fs.readFileSync('angular.js', 'utf-8');
eval(angular_file);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.