Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

455
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!