如何从Node.js中的URL加载外部js脚本

时间:2022-10-12 18:18: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:

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

http://example.com/api/js

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

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

Thanks!

1 个解决方案

#1


4  

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

exec('wget http://example.com/api/js',function(stdout){});应该做的伎俩。如果需要高级控制,请使用http模块

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

#1


4  

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

exec('wget http://example.com/api/js',function(stdout){});应该做的伎俩。如果需要高级控制,请使用http模块

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