URL Shortener is a web application that allows users to shorten long URLs for easier sharing and management. This project is built using Node.js and demonstrates server-side scripting, database management, and RESTful API development.
- Shorten URLs: Convert long URLs into short, manageable links.
- Redirect: Redirect users to the original URL when they access the shortened link.
- API Endpoints: Provide RESTful API endpoints for URL shortening and redirection.
- Node.js: JavaScript runtime for building server-side applications.
- Express.js: Web framework for Node.js to handle routing and middleware.
- MongoDB: NoSQL database for storing URL mappings.
- Clone the repository:
git clone https://github.com/KARANSINGH34951/short-url-using-Node
- Navigate to the project directory:
cd url-shortener
- Install dependencies:
npm install
- Set up environment variables:
Create a
.env
file in the root directory and add your MongoDB connection string:MONGODB_URI=your_mongodb_connection_string
- Start the server:
npm start
- Access the application:
Open your browser and go to
http://localhost:3000
. - Shorten a URL: Enter a long URL in the input field and click "Shorten".
- Use the shortened URL: Copy the shortened URL and share it. Accessing this URL will redirect to the original long URL.
-
POST /shorten: Shortens a given long URL.
- Request Body:
{ "longUrl": "http://example.com" }
- Response:
{ "shortUrl": "http://short.url/abc123" }
- Request Body:
-
GET /:shortUrl: Redirects to the original long URL.
url-shortener/
├── config/
│ ├── db.js
├── controllers/
│ ├── urlController.js
├── models/
│ ├── Url.js
├── routes/
│ ├── urlRoutes.js
├── views/
│ ├── index.html
├── .env
├── .gitignore
├── package.json
├── server.js
└── ...
Contributions are welcome! Please fork the repository and use a feature branch. Pull requests are warmly welcomed.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or feedback, feel free to contact me at [[email protected]].