我終於明白了。本示例下載文件http://javascript-modules.googlecode.com/svn/functionChecker.js,然後將其保存在本地目錄中。
//var functionChecker = require(__dirname + '/functionChecker.js');
//functionChecker.checkAllFunctions(__filename);
var http = require('http');
var fs = require('fs');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/svn/functionChecker.js',
{'host': 'javascript-modules.googlecode.com'});
request.end();
out = fs.createWriteStream('functionChecker.js');
request.on('response', function (response) {
response.setEncoding('utf8');
response.on('data', function (chunk) {
out.write(chunk);
});
});
//function name: stuff
//requires functions: false
//is defined: false
//description: blah blah woohoo.
一種選擇是將腳本下載到本地目錄,然後像其他任何模塊一樣將其導入。 –
可能相關:http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js –
這段代碼片段解決了我的問題:http://stackoverflow.com/a/4174157/975097 –