我正在尝试用nodejs的WGET方法进行文件下载。我发现了这个:
var exec = require('exec');
// Function to download file using wget
var download_file_wget = function(file_url) {
// extract the file name
var file_name = url.parse(file_url).pathname.split('/').pop();
// compose the wget command
var wget = 'wget -P ' + DOWNLOAD_DIR + ' ' + file_url;
// excute wget using child_process' exec function
var child = exec(wget, function(err, stdout, stderr) {
if (err) throw err;
else console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
});
};但上面写着:
Error: Cannot find module 'exec'exec是要安装和导入的另一个模块吗?或者我怎么才能让它工作呢?
发布于 2012-06-20 11:37:29
是的,url是内置的节点模块之一
只管去做
var url = require('url');在你档案里的某个地方。
exec是child_process的一部分,所以要实现它
var exec = require('child_process').exec;https://stackoverflow.com/questions/11112466
复制相似问题