How to load external js script from URL in Node.js

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!

Answers:

Answer

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

http://docs.nodejitsu.com/articles/HTTP/clients/how-to-create-a-HTTP-request

Answer

Use GGScript.

const GGScript = require("ggscript")
GGScript("http://example.com/api/js").then(() => {
    console.log("Finished loading file.")
})

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.