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

前端 未结 2 1377
长情又很酷
长情又很酷 2021-01-19 04:26

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
<         


        
相关标签:
2条回答
  • 2021-01-19 04:43

    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

    0 讨论(0)
  • 2021-01-19 05:01

    Use GGScript.

    const GGScript = require("ggscript")
    GGScript("http://example.com/api/js").then(() => {
        console.log("Finished loading file.")
    })
    
    0 讨论(0)
提交回复
热议问题