如何从Node.js中的URL加载外部js脚本 [英] How to load external js script from URL in Node.js

查看:155
本文介绍了如何从Node.js中的URL加载外部js脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在VPS上运行的node.js服务器,我想使用从另一台服务器提供的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

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

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

谢谢!

推荐答案

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

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请求

这篇关于如何从Node.js中的URL加载外部js脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆