7

I want to send multiple files to the user per response. For example the user requests the index site, and the site needs some .png´s, the css and so on.

The user only get a package with all he needs. Thats the idea.

So my idea is that it will be realize in something like this way:

      res.writeHead(200, {'Content-Type': 'text/html'});

      var content = fs.readFileSync(applicationPath + "index.html");
      res.write(content);
      content = fs.readFileSync(applicationPath + "images/logo.png");
      res.write(content);
      content = fs.readFileSync(applicationPath + "index.css");
      res.write(content);

      res.end();

Is this possible in any way? Or are there other solutions for that?

Thank you for your help and answers!

Dominik Nöth
  • 185
  • 2
  • 8
  • See https://stackoverflow.com/questions/1041542/how-to-download-multiple-files-with-one-http-request – trinalbadger587 Aug 04 '21 at 05:38
  • Does this answer your question? [How to download multiple files with one HTTP request?](https://stackoverflow.com/questions/1041542/how-to-download-multiple-files-with-one-http-request) – trinalbadger587 Aug 04 '21 at 05:38

1 Answers1

0

One solution you pinned it by saying "package". Put the files in a archive and send one file res.write(archive_content). Of course change the content-type accordingly.

How to create the archive here: Compressing multiple files using zlib

Community
  • 1
  • 1
Jinxmcg
  • 1,830
  • 1
  • 21
  • 24