【问题标题】:NodeJS File Downloader with WGET?带有 WGET 的 NodeJS 文件下载器?
【发布时间】:2012-06-20 03:35:01
【问题描述】:

我正在尝试使用 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 是另一个要安装和导入的模块吗.. 或者我怎样才能让它工作?

【问题讨论】:

    标签: http node.js download exec wget


    【解决方案1】:

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

    做事

    var url = require('url');
    

    在您文件中的某个位置。

    exec 是child_process 的一部分,所以要这样做

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

    【讨论】:

    • 哦.. url 没有解决,但又为exec 解决了,但我不能包含var exec = require('exec'); 是否要安装?
    • 你可能想做var exec = require('child_process').exec - 这些东西可以很容易地在 API 文档中找到 - nodejs.org/api
    • 噢耶!就是这样,吉姆。所以现在我将问题更改为大约exec 然后将您的答案作为新答案。因为我想把它作为一个接受的答案。谢谢;)
    猜你喜欢
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    相关资源
    最近更新 更多