Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/ashif1996/snap-url-shortener
- Owner: ashif1996
- Created: 2024-11-10T14:52:08.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-01-06T15:34:53.000Z (3 days ago)
- Last Synced: 2025-01-06T16:38:36.409Z (3 days ago)
- Topics: bootstrap5, css, ejs, expressjs, html5, javascript, mongodb, nodejs
- Language: JavaScript
- Homepage:
- Size: 202 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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! ๐