Converting JPG to PNG with Node.js

This guide shows how to convert a JPG image to PNG 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.jpg")
  .png()
  .toFile("image.png");

Run with:

node example.js