Converting PNG to JPG with Node.js

This guide shows how to convert a PNG image to JPG in Node.js with the Sharp package. If you would like to know more read the main article.

Install Sharp:

npm i sharp

Create a file (e.g. example.js) with the following contents:

example.js
import sharp from "sharp";

await sharp("image.png")
  .jpeg()
  .toFile("image.jpg");

Run with:

node example.js