开发者

NodeJS - use remote module?

开发者 https://www.devze.com 2023-02-26 23:19 出处:网络
I\'m working with node and would like to include a module stored on a remote server in my app. I.E. I\'d like to do s开发者_开发百科omething along these lines (which does not work as is):

I'm working with node and would like to include a module stored on a remote server in my app.

I.E. I'd like to do s开发者_开发百科omething along these lines (which does not work as is):

var remoteMod = require('http:// ... url to my remote module ... ');

As a workaround I'd be happy with just grabbing the contents of the remote file and parsing out what I need if that's easier - though I haven't had much luck with that either. I have a feeling I'm missing something basic here (as I'm a relative beginner with node), but couldn't turn up anything after scouring the docs.

EDIT:

I own both local and remote servers so I'm not concerned with security issues here.

If I'm just going to grab the file contents I'd like to do so this synchronously. Using require('http').get can get me the file, but working from within the callback is not optimal for what I'm trying to do. I'd really be looking for something akin to php's fopen function - if that's even doable with node.


Running code loaded from another server is very dangerous. What if someone can modify this code? This person would be able to run every code he wants on your server.


You can grab remote file just via http http://nodejs.org/docs/v0.4.6/api/http.html#http.get

require('http').get({host: 'www.example.com', path: '/mystaticfile.txt'}, function(res) {
 //do something
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号