question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is your feature request related to a problem? Please describe.

squoosh has CLI, so I think it is possible to implement Node.js API

Describe the solution you’d like

Adding Node.js API

Does other service/app have this feature?

For example - imagemin have CLI and Node.js API

Additional context

The Node.js API will allow squoosh to be used in other tools, for example I am developers https://github.com/webpack-contrib/image-minimizer-webpack-plugin and now we use imagemin for this, but setup is complex and unable on some platform because libraries for compression compiled on developer machine

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:15
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tomByrercommented, Feb 22, 2021

@alexander-akait in the meanwhile, you can use exec or it’s asyc sister. Actually might be better to always run CLI this way (after adding commander or yargs) for a CLI if one uses the same pattern often.

const { exec } = require("child_process")

let file = './img/codepen.io-2021-02-15.png'
let rounds = 2
let bt = 1.1

exec(`squoosh-cli -s .r${rounds}bt${bt} --avif --max-optimizer-rounds ${rounds} --optimizer-butteraugli-target ${bt} -d out ${file}`,  (error, stdout, stderr) => {
	if (error) {
			console.log(`error: ${error.message}`);
			return;
	}
	if (stderr) {
			console.log(`stderr: ${stderr}`);
			return;
	}
	console.log(`🎆 success!
${stdout}`);
})
3reactions
surmacommented, Jan 14, 2021

Yup, at some point I want to re-factor the CLI to have a proper separation between a libsquoosh and the cli

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Secure Node.js REST API - Toptal
REST APIs are so useful and ubiquitous that every web developer should know how to build them. Here's how to build a Node.js...
Read more >
Build Node.js RESTful APIs in 10 Minutes | Codementor
In this tutorial, we will learn how to create a RESTful API using Node.js. Tools: Node.js; MongoDB; Text editor (Atom, Sublime, etc) (Read...
Read more >
Build a web API with Node.js and Express by using JavaScript
Use Express for Node.js to build RESTful APIs. Create and configure middleware to add things like logging, authentication and authorization, and other web ......
Read more >
How to Build a Node.js REST API in Simple Steps
Steps to Build REST API with Node.js ... Interface IGetAccountContext extends Context<IAuthenticateContext & IParamsContext<"id">> {} export const ...
Read more >
How to Build REST API with Node.js from Scratch - Edureka
Practical Demonstration: Building REST API using Node.js ... Here, we will be creating a simple CRUD REST application for Library Management using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found