0

I am trying to create a zip file in node using the code provided from how to create a zip file in node given multiple downloadable links, as shown below:

var fs = require('fs');
var archiver = require('archiver');
var output = fs.createWriteStream('./example.zip');
var archive = archiver('zip', {
    gzip: true,
    zlib: { level: 9 } // Sets the compression level.
});

archive.on('error', function(err) {
  throw err;
});

// pipe archive data to the output file
archive.pipe(output);

// append files
archive.file('/path/to/file0.txt', {name: 'file0-or-change-this-whatever.txt'});
archive.file('/path/to/README.md', {name: 'foobar.md'});

//
archive.finalize();

When I use this suggestion, the zip file is downloaded without any kind of prompt asking me where I would like to save the file - is there any way I can make it so that a prompt is created asking me where I would like to save the file, which is quite normal these days?

If this is absolutely not possible, would it be possible to always save the file in the downloads folder (regardless of whether on mac or windows or any other operating system)?

user11508332
  • 537
  • 1
  • 11
  • 28

1 Answers1

0

So there's a couple of things here. In terms of a 'prompt' or 'pop-up' you won't find anything along the lines of WinForms out of the box, there are options for the command line such as prompts You can use that as your user input.

https://www.npmjs.com/package/prompts

You'll want to use path and more specifically path.join() to combat the mac/windows/linux issue.

Do you need to use path.join in node.js?

You can run an express server and create a route that uses res.download() in which you would provide the zipped file.

https://expressjs.com/en/api.html#res.download

razki
  • 1,171
  • 2
  • 8
  • 16
  • so when I say prompts for download location, I mean something like the thing that shows when you try to download atom from https://atom.io/, and directs you to choose a location for the download - does the prompts package do this kind of thing? – user11508332 Apr 11 '20 at 15:25