简体   繁体   English

返回带有Node.js的下载文件路径?

[英]Return downloaded file path with Node.js?

I use the download npm module to download a file. 我使用download npm模块下载文件。

But I need the get the downloaded file path to launch the installation. 但是我需要获取下载的文件路径来启动安装。

// Dependencies.
var cheerio = require('cheerio'),
    request = require('request'),
    download = require('download')
    fs = require('fs');

// Download and install latest Chromium build.
function getChromium() {

    request('http://chromium.woolyss.com/download/', function (err, res, html) {
        var $ = cheerio.load(html);
        var link = $('#p-windows > div > p:nth-child(2) > span:nth-child(13) > a').attr('href');
        download(link, 'apps', { extract: false });
        // What should I do now?
    });

}

getChromium();

Is it possible? 可能吗? How can I do? 我能怎么做?

Thanks 谢谢

From the Usage section of the documentation it looks like you can specify both a download link and local filename in the first parameter, like this: 在文档的“ 用法”部分,您似乎可以在第一个参数中同时指定下载链接和本地文件名,如下所示:

download({ url: link, name: 'chromium.zip' }, 'apps', { extract: false });

That will save the bundle to 'apps/chromium.zip' . 这会将捆绑'apps/chromium.zip'保存到'apps/chromium.zip'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM