我正在尝试使用 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
是另一个要安装和导入的模块吗?或者我怎样才能让它工作?
最佳答案
是的,url
是内置 Node 模块之一
就这样
var url = require('url');
在你的文件中的某处。
exec
是 child_process
的一部分所以要做到这一点
var exec = require('child_process').exec;
关于http - 带有 WGET 的 NodeJS 文件下载器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11112466/