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

456
Vistas
Am Using tinify in node js. Wow can we download supressed file using nodejs?

I am using npm install --save tinify then uploading my image files using nodejs but I need compressed .zip file in my system .

When I'm uploading my image files through browser at https://tinypng.com after uploading it shows download option that is perfect. But how can we do same through nodejs?

Here is my code:

var tinify = require("tinify");
tinify.key = "myRightApiCode";
var fs = require("fs");

fs.readFile("C:/Users/sourav/images/pgL_NA-10005_5.jpg", function(err, 
sourceData) {
if (err) throw err;
tinify.fromBuffer(sourceData).toBuffer(function(err, resultData) {
if (err) throw err;
// ...
console.log(resultData);
//need compressed file in my system
});
}); 
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use tinify's method that converts and writes the compressed image at once:

var sourceFile = tinify.fromFile("uncompressed.jpg");
sourceFile.toFile("compressed.jpg");

Alternatively in your method try:

var tinify = require("tinify");
tinify.key = "myRightApiCode";
var fs = require("fs");

fs.readFile("C:/Users/sourav/images/pgL_NA-10005_5.jpg", function(err, 
sourceData) {
    if (err) throw err;
    tinify.fromBuffer(sourceData).toBuffer(function(err, resultData) {
        if (err) throw err;

        fs.writeFile('C:/Users/sourav/images/optimized.jpg', resultData, function (err) {
            if (err) throw err;
            console.log('It\'s saved!');
        });

    });
}); 

Hope this solves your query :)

over 4 years ago · Santiago Trujillo 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