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.
- 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.
- Node.js: Fast and scalable JavaScript runtime.
- Express.js: Flexible and minimalist web framework.
- MongoDB: NoSQL database for storing URLs and related metadata.
- 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.
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
- Node.js (v16+ recommended)
- MongoDB (local instance or MongoDB Atlas)
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/your-username/snap-url-shortener.git cd snap-url-shortener
-
Install dependencies:
npm install
-
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
-
Set up MongoDB:
- Ensure MongoDB is running on your system or accessible remotely.
- Create a database with the name specified in the
.env
file.
-
Run the application:
npm start
-
Open your browser and navigate to:
http://localhost:3000
-
Home Page
- Enter a long URL to get a shortened version.
- Copy or share the shortened URL directly.
-
Error Pages
- Encounter custom error pages for 404 or internal server issues.
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
- 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.
This project is licensed under the MIT License.
- Thanks to the open-source community for libraries and tools used in this project.
Happy Shortening! π