Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js Image Upload, Processing, and Resizing using Sharp Package

Node.js Image Upload, Processing, and Resizing using Sharp Package

Posted on November 11, 2025November 11, 2025 By Rishabh saini No Comments on Node.js Image Upload, Processing, and Resizing using Sharp Package

Node.js Image Upload, Processing, and Resizing using Sharp Package

In this article, we will explore how to handle image upload, processing, and resizing in Node.js using the Sharp package with an example implementation.

Handling multiple image formats efficiently is essential in modern web applications—whether for profile pictures, thumbnails, or product images in e-commerce platforms. The challenge lies in optimizing image sizes without degrading their quality. To ensure that images look sharp across different devices and screen resolutions, developers often need to generate multiple optimized versions. Achieving the right balance between file size, image quality, and performance requires effective compression and image storage techniques.

Data Science Tutorial:–Click Here

Modules Used: Sharp, Multer

According to the official npm documentation, Sharp is a high-performance image processing library that converts large image files (such as JPEG, PNG, and WebP) into smaller, optimized, web-friendly versions. It allows resizing, compressing, and converting images into different formats, resulting in faster load times and better website performance.

Sharp is particularly beneficial for applications requiring rapid image delivery and efficient data handling. By reducing large image files into lightweight, high-quality alternatives, it helps enhance overall user experience and web responsiveness.

Introduction to Applied AI:–Click Here

What is the Sharp Module?

Sharp is a powerful and fast Node.js library used for image conversion and manipulation. It supports popular formats like JPEG, PNG, WebP, GIF, and AVIF, and allows developers to resize and transform images effortlessly.

Sharp is compatible with JavaScript runtimes that support Node-API v9, including Node.js (~18.17.0 or ≥20.3.0), Deno, and Bun. It is powered by libvips, which makes image processing operations up to 4–5 times faster than traditional tools like ImageMagick or GraphicsMagick.

Sharp efficiently manages color spaces, transparency channels, and ICC profiles, ensuring high-quality image output. It also supports advanced operations such as gamma correction, rotation, compositing, and region extraction, making it one of the most comprehensive image processing solutions for Node.js.

Download New Real Time Projects :–Click here

What is the Multer Module?

Multer is a middleware for handling multipart/form-data in Node.js, commonly used for file uploads. Built on top of Busboy, it provides efficient handling of form submissions that include file data.

When users upload files through forms, Multer processes the incoming data and attaches two objects to the request:

  • req.body → contains text fields
  • req.file → contains information about uploaded files

Multer offers flexible configuration options, such as custom storage engines, upload destinations, and file size/type limitations, ensuring secure and efficient file handling.

This makes Multer an essential tool for any Node.js application dealing with file uploads, particularly when combined with Sharp for image processing.

SQL Tutorial :–Click Here

Example: Uploading, Processing, and Resizing Images Using Sharp

Here’s a simple example demonstrating how to upload an image, process it, and resize it using Multer and Sharp.

const express = require('express');  
const multer = require('multer');  
const sharp = require('sharp');  
const path = require('path');  
const fs = require('fs');  

const app = express();  
const port = 3000;  

// Set up storage engine for multer  
const storage = multer.diskStorage({  
  destination: (req, file, cb) => {  
    const uploadPath = './uploads';  
    if (!fs.existsSync(uploadPath)) {  
      fs.mkdirSync(uploadPath);  
    }  
    cb(null, uploadPath);  
  },  
  filename: (req, file, cb) => {  
    cb(null, Date.now() + path.extname(file.originalname));  
  }  
});  

// Initialize multer with storage settings  
const upload = multer({ storage: storage });  

// Endpoint to upload image  
app.post('/upload', upload.single('image'), (req, res) => {  
  if (!req.file) {  
    return res.status(400).send('No file uploaded');  
  }  

  const filePath = req.file.path;  
  const resizedFilePath = filePath.replace(path.extname(filePath), '-resized' + path.extname(filePath));  

  // Resize image using Sharp  
  sharp(filePath)  
    .resize(300, 300)  
    .toFile(resizedFilePath, (error, info) => {  
      if (error) {  
        console.log('Error resizing image:', error);  
        return res.status(500).send('Error processing image');  
      }  
      console.log('Image resized successfully:', info);  
      res.send(`Image uploaded and resized successfully. Resized image path: ${resizedFilePath}`);  
    });  
});  

// Start the server  
app.listen(port, () => {  
  console.log(`Server running at http://localhost:${port}`);  
});

Output Example:

No file uploaded

Explanation:

This Node.js application demonstrates how Express, Multer, and Sharp work together to handle image uploads and resizing:

Deep Learning Tutorial:– Click Here

  1. Express sets up the web server and routing.
  2. Multer handles file uploads and stores them in the ./uploads directory, automatically generating unique filenames using timestamps.
  3. The /upload endpoint receives the uploaded file, and Sharp processes it by resizing it to 300×300 pixels.
  4. The resized image is saved with a -resized suffix, and its path is returned in the response.
  5. If any errors occur during upload or processing, appropriate error messages are sent back.

Once the server is running, you can test the upload by sending an image through a form or an API tool like Postman to http://localhost:3000/upload.

Machine Learning Tutorial:–Click Here
Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click Here


node js image upload processing and resizing using sharp package online node js image upload processing and resizing using sharp package java sharp npm sharp nodejs sharp node js documentation sharp nodejs example sharp next js nodejs sharp resize image simple api for resizing image using typescript and sharp, resize an image in node.js using sharp, image optimization with nodejs using sharp, node js image upload and compress, nodejs image processing, nodejs sharp resize image, sharp image processing, image procesing using node js by url, sharp image processing library, node.js image processing, resize image using node.js, node.js upload image resize, node.js image upload, node js sharp resize image, node upload resize image

    Post Views: 208
    Node.js Tutorial Tags:image optimization with nodejs using sharp, image procesing using node js by url, node js image upload and compress, node js sharp resize image, node.js image processing, node.js image upload, node.js upload image resize, nodejs image processing, nodejs sharp resize image, resize an image in node.js using sharp, resize image using node.js, sharp image processing, sharp image processing library, simple api for resizing image using typescript and sharp

    Post navigation

    Previous Post: Best Quiz Management System Using MERN Stack
    Next Post: Best leave Management System Using MERN-Based Web Application

    More Related Articles

    Node.js vs Java Node.js vs Java – Python Project with Source Code Node.js Tutorial
    Node.js Process Node.js Process Node.js Tutorial
    Node.js MongoDB Create a Database Node.js MongoDB Create a Database Node.js Tutorial

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may also like

    1. Install Nodejs on Windows
    2. Node.js Command Line Options
    3. Node.js Child Process
    4. Node.js Assertion Testing
    5. Node.js MySQL Update Records
    6. Node.js MySQL Delete Records

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Online Bike Rental Management System Using PHP and MySQL
    9. E learning Website in php with Free source code
    10. E-Commerce Website Project in Java Servlets (JSP)
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
    • Online Job Portal System in JSP Servlet MySQL

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,615)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,218)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,872)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme