Skip to content

AugustoLL/Qr-Code-Generator-Backend

Repository files navigation

QR Code Generator Backend

License Node.js Version npm Version axios Version Express Version express-rate-limit Version nodemon Version dotenv Version joi Version memory-cache Version morgan Version qrcode Version sharp Version valid-url Version winston Version winston-daily-rotate-file Version

This is a simple QR code generator made with Node.js and Express.

❗️ Features

  • Generate QR codes with customizable options:
    • URL to encode
    • Image format (PNG, JPEG, WebP)
    • Size
    • Error correction level
    • Dark and light colors
    • Logo overlay with customizable size ratio
  • Cache QR codes for improved performance
  • Clear cache manually through API endpoint

🖼️ Examples

Example 1: Simple Black and White QR Code

http://localhost:8080/api/generate?url=https://github.com/AugustoLL/Qr-Code-Generator-Backend&format=png&size=500&errorCorrectionLevel=H

Github repo QR Code

Example 2: Red and Black QR Code with YouTube Logo

http://localhost:8080/api/generate?url=https://youtube.com&format=png&size=500&errorCorrectionLevel=H&darkColor=%23FF0000&lightColor=%23000000&logoUrl=https://clipart-library.com/images_k/youtube-transparent-png/youtube-transparent-png-15.png

YouTube QR Code

Example 3: White and Light-Blue QR Code with LinkedIn Logo

http://localhost:8080/api/generate?url=https://www.linkedin.com/in/augusto-lombino-218bba18b&format=png&size=500&errorCorrectionLevel=H&darkColor=%231686B0&lightColor=%23FFFFFF&logoUrl=https://sydneysocialmediamanagers.com.au/wp-content/uploads/2017/03/Linkedin-logo.png&logoSizeRatio=0.2

LinkedIn Profile QR Code

🔨 Installation

  1. Clone the repository:

    git clone https://github.com/AugustoLL/Qr-Code-Generator-Backend.git
    cd qr-code-generator
  2. Install dependencies:

    npm install
  3. Start the server:

    npm start

The server will start on http://localhost:8080 by default.

🌎 Environment Variables

This project uses the following environment variables for configuration:

  • PORT: The port on which the server runs (default: 8080).
  • CACHE_EXPIRATION_TIME: Cache expiration time in seconds (default: 3600).
  • MAX_CACHE_SIZE: Maximum cache size (default: 100).

You can define these variables in a .env file.

Example .env File

PORT=8080
CACHE_EXPIRATION_TIME=3600
MAX_CACHE_SIZE=100

🌐 API Endpoints

Generate QR Code

GET /api/generate

Parameters

  • url: URL to encode in the QR code (required)
  • format: Image format (png, jpeg, webp; default: png)
  • size: Size of the QR code image (default: 200)
  • errorCorrectionLevel: Error correction level (L, M, Q, H; default: M)
  • darkColor: Dark color of the QR code in hex format (default: #000000)
  • lightColor: Light color of the QR code in hex format (default: #FFFFFF)
  • logoUrl: URL of the logo image to overlay on the QR code (optional)
  • logoSizeRatio: Size ratio of the logo relative to the QR code (default: 0.2)

Example

http://localhost:8080/api/generate?url=https://example.com&format=png&size=300&errorCorrectionLevel=M&darkColor=%230000FF&lightColor=%23FFFF00

Clear Cache

GET /api/clear-cache

Description

Clears the cached QR codes stored for improved performance.

📐 Usage

To generate a QR code, open your browser and navigate to:

http://localhost:8080/api/generate?url=YOUR_URL&format=png&size=200

Replace YOUR_URL with the URL you want to encode.

📦 Docker Setup

Build Docker Image

docker build -t qr-code-generator-backend .

Run Docker Container

docker run --env-file .env -p 8080:8080 qr-code-generator-backend

Alternatively, you can pass individual environment variables directly:

docker run -e NODE_ENV=production -e API_KEY=your_api_key_here -p 8080:8080 qr-code-generator

Docker Compose

To use Docker Compose, run the following command:

docker-compose up

❕ Yet to implement

  • Change the style of the shapes of the QR Code
  • Allow QR Codes for
    • contact:
      • name: name, last name
      • contact: mobile number, phone number, fax, email
      • company: company, job
      • street
      • city: name, zip
      • state
      • country
      • website
    • wifi: network name, password, encryption (none, wpa/wpa2, wep)
    • emails: address, subject, message
    • sms: number, message
  • Allow for gradients when setting the colors
  • Add Dynamic QR Codes (codes that can be updated without changing the printed code)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published