Http 用WGET下载NodeJS文件?

Http 用WGET下载NodeJS文件?,http,node.js,download,exec,wget,Http,Node.js,Download,Exec,Wget,我正在尝试使用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(); //

我正在尝试使用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
是要安装和导入的另一个模块吗。。或者如何使其工作?

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

照办

var url = require('url');
在你档案的某个地方

exec
是so的一部分

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

哦<代码>url未解决,但对于
exec
再次解决,但我不能包括
var exec=require('exec')
要安装吗?您可能想执行
var exec=require('child_process')。exec
-在API文档中可以很容易地找到这些东西-哦,耶!就是这样,吉姆先生。因此,现在我将问题改为about
exec
,然后将您的答案作为新答案移动。因为我想让它成为一个公认的答案。谢谢;)