Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

396
Vistas
Comppresing folder to zip in node.js

I'm creating a discord bot in discord.js that saves messages on the server. I would like to make it send a .zip compressed file from the saved messages folder. I know how to send attechment but I don't know how to add files from directory to this zip

I tried this:

But files aren't appending in zip.
Could someone please send fixed code?
Thank you in advance for your help.

var fs = require("fs");
var JSZip = require("jszip");
var zip = new JSZip();

zip
   .folder("data");
   .generateNodeStream({ type: 'nodebuffer', streamFiles: true })

  .pipe(fs.createWriteStream("logs.zip"))
   .on('finish', function () {
       console.log("out.zip written.");
   });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

At the Discord.js Documentation in stable version, TextChannel reference has a method send that allow send remote and local files.

Sample code of documentation for send a local file:

// Send a local file
channel.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
    description: 'A description of the file'
  }]
})
  .then(console.log)
  .catch(console.log);

You can build a absolute path file with the path module and give as attachment value.

const path = require('path');
const ABSOLUTE_PATH_FILE = path.resolve(__dirname, "./../files/filename.zip");
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda