Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ashif1996/snap-url-shortener

snapURL! is a Node.js, Express, and MongoDB-based app that shortens long URLs for easy sharing.
https://github.com/ashif1996/snap-url-shortener

bootstrap5 css ejs expressjs html5 javascript mongodb nodejs

Last synced: about 23 hours ago
JSON representation

snapURL! is a Node.js, Express, and MongoDB-based app that shortens long URLs for easy sharing.

Awesome Lists containing this project

README

        

# 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

```plaintext
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**:
```bash
git clone https://github.com/your-username/snap-url-shortener.git
cd snap-url-shortener
```

2. **Install dependencies**:
```bash
npm install
```

3. **Set up environment variables**:
Create a `.env` file in the root directory with the following contents:
```plaintext
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**:
```bash
npm start
```

6. Open your browser and navigate to:
```plaintext
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**:
```bash
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! ๐ŸŽ‰