Skip to content

π¬π§πšπ©π”π‘π‹! 𝐒𝐬 𝐚 𝐍𝐨𝐝𝐞.𝐣𝐬, π„π±π©π«πžπ¬π¬, 𝐚𝐧𝐝 πŒπ¨π§π π¨πƒπ-π›πšπ¬πžπ 𝐚𝐩𝐩 𝐭𝐑𝐚𝐭 𝐬𝐑𝐨𝐫𝐭𝐞𝐧𝐬 π₯𝐨𝐧𝐠 𝐔𝐑𝐋𝐬 𝐟𝐨𝐫 𝐞𝐚𝐬𝐲 𝐬𝐑𝐚𝐫𝐒𝐧𝐠.

Notifications You must be signed in to change notification settings

ashifhassandev/snap-url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

snapURL! - URL Shortener Application

snapURL! is a lightweight and efficient application built with Node.js, Express, and MongoDB. It allows users to shorten long URLs for easy sharing while offering a user-friendly interface and seamless backend functionality.

πŸš€ Features

  • URL Shortening: Quickly convert long URLs into concise, shareable links.
  • Error Handling: Custom error pages for 404 and server issues.
  • Email Notifications: Send emails to the admin.
  • Load Testing: YAML-based configurations for stress testing.

πŸ› οΈ Tech Stack

Backend

  • Node.js: Fast and scalable JavaScript runtime.
  • Express.js: Flexible and minimalist web framework.
  • MongoDB: NoSQL database for storing URLs and related metadata.

Frontend

  • EJS: Embedded JavaScript templates for dynamic HTML generation.
  • CSS: Custom styles for a polished and responsive UI.
  • JavaScript: Enhances interactivity and validation on the client side.

πŸ“‚ Project Structure

snap-url-shortener/
β”œβ”€β”€ config/                   # Configuration files (DB, email, etc.)
β”‚   β”œβ”€β”€ dbConfig.js           # MongoDB connection configuration
β”‚   β”œβ”€β”€ emailConfig.js        # Email service configuration
β”œβ”€β”€ controllers/              # Controllers for handling application logic
β”‚   β”œβ”€β”€ indexController.js    # Main controller for app routes
β”œβ”€β”€ models/                   # Database models
β”‚   β”œβ”€β”€ urlModel.js           # MongoDB schema for URLs
β”œβ”€β”€ public/                   # Static assets (CSS, JS, images)
β”‚   β”œβ”€β”€ css/                  # CSS files for styling
β”‚   β”œβ”€β”€ js/                   # JavaScript files for client-side functionality
β”‚   β”œβ”€β”€ 404.css               # Styling for 404 error page
β”‚   β”œβ”€β”€ loader.css            # Styling for loading animations
β”‚   β”œβ”€β”€ mainStyle.css         # Main stylesheet for the application
β”‚   β”œβ”€β”€ email.js              # Handles email interactions
β”‚   β”œβ”€β”€ loader.js             # Handles loading animations
β”‚   β”œβ”€β”€ result.js             # Handles result page logic
β”‚   β”œβ”€β”€ urlForm.js            # Handles URL form validation
β”œβ”€β”€ routes/                   # Application routes
β”‚   β”œβ”€β”€ indexRoutes.js        # Routes for main application functionality
β”œβ”€β”€ tests/                    # Load testing configurations
β”‚   β”œβ”€β”€ load-tests/           # Folder for load testing
β”‚   β”œβ”€β”€ load-test.yml         # YAML configuration for stress testing
β”œβ”€β”€ utils/                    # Utility functions
β”‚   β”œβ”€β”€ emailUtils.js         # Helper functions for email operations
β”‚   β”œβ”€β”€ httpStatusCodes.js    # Standard HTTP status codes
β”‚   β”œβ”€β”€ responseUtils.js      # Utility functions for API responses
β”‚   β”œβ”€β”€ urlShortener.js       # Core URL shortening logic
β”œβ”€β”€ views/                    # EJS templates for rendering views
β”‚   β”œβ”€β”€ layout/               # Layout templates
β”‚   β”œβ”€β”€ partials/             # Reusable components like header and footer
β”‚   β”œβ”€β”€ 404.ejs               # 404 error page template
β”‚   β”œβ”€β”€ about.ejs             # About page
β”‚   β”œβ”€β”€ contact.ejs           # Contact page
β”‚   β”œβ”€β”€ index.ejs             # Homepage for URL shortening
β”‚   β”œβ”€β”€ internalError.ejs     # Internal server error page
β”‚   β”œβ”€β”€ result.ejs            # Page displaying the shortened URL
β”œβ”€β”€ .gitignore                # Ignored files and folders for Git
β”œβ”€β”€ README.md                 # Project documentation
β”œβ”€β”€ app.js                    # Main application entry point
β”œβ”€β”€ package.json              # Node.js dependencies and metadata
β”œβ”€β”€ package-lock.json         # Lock file for dependencies

πŸ”§ Setup and Installation

Prerequisites

  • Node.js (v16+ recommended)
  • MongoDB (local instance or MongoDB Atlas)
  • npm (Node Package Manager)

Steps

  1. Clone the repository:

    git clone https://github.com/your-username/snap-url-shortener.git
    cd snap-url-shortener
  2. Install dependencies:

    npm install
  3. Set up environment variables:
    Create a .env file in the root directory with the following contents:

    PORT=3000
    DB_USER=your_db_user
    DB_PASSWORD=your_db_password
    DB_HOST=your_db_host
    DB_PORT=27017
    DB_NAME=your_db_name
    SESSION_SECRET=your_session_secret
    SEND_EMAIL=your_email
    SEND_EMAIL_PASS=your_email_password
    
  4. Set up MongoDB:

    • Ensure MongoDB is running on your system or accessible remotely.
    • Create a database with the name specified in the .env file.
  5. Run the application:

    npm start
  6. Open your browser and navigate to:

    http://localhost:3000
    

πŸ“œ Usage

  1. Home Page

    • Enter a long URL to get a shortened version.
    • Copy or share the shortened URL directly.
  2. Error Pages

    • Encounter custom error pages for 404 or internal server issues.

πŸ§ͺ Load Testing

The tests/load-tests/load-test.yml file provides a configuration for performing stress tests on the application. Use tools like Artillery to execute these tests.

Run the load test:

artillery run tests/load-tests/load-test.yml

πŸ“ˆ Learning Outcomes

  • Building a URL shortener with Node.js, MongoDB, and Express.
  • Understanding dynamic EJS templates for rendering views.
  • Managing database connections with MongoDB.
  • Implementing robust email notifications and error handling.
  • Learning load testing to ensure application scalability.

πŸ“œ License

This project is licensed under the MIT License.

🌟 Acknowledgements

  • Thanks to the open-source community for libraries and tools used in this project.

Happy Shortening! πŸŽ‰

About

π¬π§πšπ©π”π‘π‹! 𝐒𝐬 𝐚 𝐍𝐨𝐝𝐞.𝐣𝐬, π„π±π©π«πžπ¬π¬, 𝐚𝐧𝐝 πŒπ¨π§π π¨πƒπ-π›πšπ¬πžπ 𝐚𝐩𝐩 𝐭𝐑𝐚𝐭 𝐬𝐑𝐨𝐫𝐭𝐞𝐧𝐬 π₯𝐨𝐧𝐠 𝐔𝐑𝐋𝐬 𝐟𝐨𝐫 𝐞𝐚𝐬𝐲 𝐬𝐑𝐚𝐫𝐒𝐧𝐠.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published