Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Processing Service

Description

This is an Image Processing Service built with Node.js, Express, TypeScript, and Mongoose. It allows users to upload, transform, and retrieve images using Cloudinary for storage. The service supports transformations such as resizing, cropping, rotating, watermarking, and applying filters.


Features

  • User Authentication
    • Register and Login users
    • JWT authentication for secure endpoints
  • Image Upload & Management
    • Upload images to Cloudinary
    • Retrieve images
    • List all uploaded images by the user
  • Image Transformation
    • Resize, Crop, Rotate, Flip, Mirror
    • Add Watermarks
    • Convert formats (JPEG, PNG, etc.)
    • Apply filters (Grayscale, Sepia, etc.)
  • Rate Limiting
    • Prevent excessive API requests using a rate limiter

Tech Stack

  • Backend: Node.js, Express.js, TypeScript
  • Database: MongoDB (Mongoose ORM)
  • Authentication: JWT
  • File Storage: Cloudinary
  • Security: Rate Limiting with express-rate-limit

Installation & Setup

Prerequisites

  • Node.js (v16 or later)
  • MongoDB (local or cloud instance)
  • Cloudinary Account (for image storage)

Clone the repository

git clone https://github.com/your-repo/image-processing-service.git
cd image-processing-service

Install dependencies

npm install

Configure environment variables

Create a .env file in the root directory and add:

PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
RATE_LIMIT_WINDOW=15
RATE_LIMIT_MAX=100

Run the server

npm run dev

The server will start on http://localhost:5000.


API Endpoints

Authentication

Register

POST /register

Request Body:

{
  "username": "user1",
  "password": "password123"
}

Response:

{
  "user": { "id": "123", "username": "user1" },
  "token": "your_jwt_token"
}

Login

POST /login

Request Body: Same as Register

Response: JWT Token


Image Management

Upload an Image

POST /images

Request Body: Multipart form-data with image file

Response:

{
  "url": "https://res.cloudinary.com/...",
  "metadata": { "width": 500, "height": 500 }
}

Apply Transformations

POST /images/:id/transform

Request Body:

{
  "transformations": {
    "resize": { "width": 300, "height": 300 },
    "crop": { "width": 100, "height": 100, "x": 10, "y": 10 },
    "rotate": 90,
    "filters": { "grayscale": true }
  }
}

Retrieve an Image

GET /images/:id

Response: Image metadata and URL

List Images (Paginated)

GET /images?page=1&limit=10

Rate Limiting

To prevent excessive API requests, the service uses express-rate-limit. The default settings allow 100 requests per 15 minutes per IP address. You can modify these settings in the .env file:

RATE_LIMIT_WINDOW=15   # Time window in minutes
RATE_LIMIT_MAX=100     # Max requests per window per IP

If the rate limit is exceeded, the server will return a 429 Too Many Requests response.


License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages