【问题标题】:How to load external js script from URL in Node.js如何从 Node.js 中的 URL 加载外部 js 脚本
【发布时间】:2014-08-30 17:03:25
【问题描述】:

我有一个在 VPS 上运行的 node.js 服务器,我想使用从另一台服务器提供的 js 脚本,例如:

http://example.com/api/js

如何加载此脚本并在我的 node.js 文件中使用它?

谢谢!

【问题讨论】:

标签: javascript node.js


【解决方案1】:

exec('wget http://example.com/api/js', function(stdout) { }); 应该可以解决问题。如果您需要高级控制,请使用http 模块。

【讨论】:

    【解决方案2】:

    使用GGScript

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

    【讨论】:

    • 为此我首先需要 GGScript :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    相关资源
    最近更新 更多