Skip to content

narayan-sahu/URL-shortner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

An URL shortener application built with Node.js, Express, and MongoDB. This project allows users to shorten long URLs and redirect to the original URL using the shortened version.

Features

  • Shorten long URLs
  • Redirect to original URLs using the shortened URL
  • Simple and clean user interface
  • Environment-based configuration

Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB (using Mongoose ODM)
  • Environment Configuration: dotenv

Live Demo

Check out the live deployment of the URL Shortener: https://url-shortner-d80u.onrender.com

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js installed on your machine
  • MongoDB server or MongoDB Atlas account
  • Git installed on your machine

Getting Started

1. Clone the Repository

git clone https://github.com/yourusername/url-shortener.git
cd url-shortener

2. Install Dependencies

npm install

3. Set Up Environment Variables

MongoUrl="mongodb+srv://username:[email protected]/yourdbname?retryWrites=true&w=majority"
PORT=3000

4. Run the Application

npm start

Project Structure

.
├── Controllers
│   └── url.js              # URL shortener logic
├── Models
│   └── Url.js              # Mongoose schema for storing URLs
├── Views
│   └── server.ejs          # EJS template for the frontend
├── .env                    # Environment variables
├── .gitignore              # Ignored files and directories
├── package.json            # Node.js dependencies and scripts
├── server.js               # Main application file
└── README.md               # Project documentation

API Endpoints

Request Body:

{
  "longUrl": "https://www.example.com"
}

Response:

{
  "shortUrl": "http://localhost:3000/abc123"
}

Acknowledgements