NodeJS文件下载与WGET?

我正在尝试使用nodejs的WGET方法创build文件下载。 我find了这个:

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另一个模块进行安装和导入..或者我怎样才能使它工作?

是的, url是内置的节点模块之一

做就是了

 var url = require('url'); 

在你的文件的某个地方。

execchild_process一部分,所以得到它

 var exec = require('child_process').exec;