0

How do you include/import JavaScript file(s) in node.js from an external URL?
I have tried include("http://example.com/script.js"); which did not work. I have seen Load and execute external js file in node.js with access to local variables. However I want to include a script from another domain. I want to have something similar to this in HTML.

<script src="http://example.com/script.js"></script>
<script>
    //do stuff
</script>

I am using Express.js.

Community
  • 1
  • 1
Kyle
  • 60
  • 10
  • Interesting question, but I don't think it's possible. At least not using require(). I just looked at node's [module documentation](https://nodejs.org/api/modules.html) and I didn't see anything suggesting it could be done. Maybe using http.request()? Then you'd still have to figure out how to load the module in the app. – Nocturno Oct 22 '15 at 01:11
  • I know i lead you unto another abandoned question, but as you will see the way to go is as Nocturno describes, http.get the source and eval. – Andreas Louv Oct 22 '15 at 01:13

0 Answers0