This repository contains a simple URL shortener application built with Node.js, utilizing the dotenv package for environment variables and MongoDB for data storage.
- Shorten long URLs to short, manageable links.
- Store the original URL and corresponding shortened URL in the MongoDB database.
- Redirect users to the original URL when they visit the shortened link.
Make sure you have the following installed on your machine:
- Node.js: Download and install Node.js.
- MongoDB: Download and install MongoDB.
-
Clone the repository:
git clone https://github.com/islombek124/url-shortener-nodejs.git
-
Navigate to the project directory:
cd url-shortener-nodejs
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory of the project and set the following environment variables:MONGO_URI=your_mongodb_connection_string PORT=3000
Replace
your_mongodb_connection_string
with the actual MongoDB connection string, e.g.,mongodb://localhost:27017/url_shortener_db
. -
Start the server:
npm run dev
The server should now be running at
http://localhost:3000
.
-
Access the URL Shortener App by visiting
http://localhost:3000
in your web browser. -
To shorten a URL, enter the long URL in the provided input field and click the "Shorten" button.
-
The application will generate a shortened URL that you can copy and share.
-
When users visit the shortened URL, they will be redirected to the original URL.
Contributions are welcome! If you find any bugs or want to improve the app, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
- This app is built using Node.js, Express, dotenv, MongoDB and ShortId.
- The project structure is inspired by Web Dev Simplified.
This app is meant for educational and demonstration purposes only. It is not suitable for production environments without proper security measures and validations. Use at your own risk.