Nodejs sends multiple files per response

I want to send multiple files to the user for each response. For example, a user requests an index site, and the site needs some .png's, css and so on.

The user only gets the package they want. This is the idea.

So my idea is that it will implement something like this:

      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 anyway? Or are there other solutions for this?

Thanks for your help and answers!

+3


source to share


1 answer


You pinned one solution by saying "package". Put the files in the archive and upload one file res.write (archive_content). Of course, change your content type accordingly.



How to create an archive here: Compressing multiple files with zlib

0


source







All Articles