4

I have a node.js server running on a VPS and I want to use a js script that is served from another server, something like:

http://example.com/api/js

How do I load this script and use it in my node.js file?

Thanks!

gsobrevilla
  • 243
  • 2
  • 12
  • Maybe download the script and then copy paste it into your file? Otherwise check this http://stackoverflow.com/questions/4481058/load-and-execute-external-js-file-in-node-js-with-access-to-local-variables – theodore hogberg Aug 30 '14 at 17:06

2 Answers2

4

exec('wget http://example.com/api/js', function(stdout) { }); should do the trick. If you need advanced control, use http module.

H.Sarxha
  • 133
  • 2
  • 9
eguneys
  • 5,648
  • 7
  • 27
  • 51
0

Use GGScript.

const GGScript = require("ggscript")
GGScript("http://example.com/api/js").then(() => {
    console.log("Finished loading file.")
})
Richie Bendall
  • 5,657
  • 3
  • 32
  • 49