This is the boilerplate code for the URL Shortener Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice.
This project is a solution to a FreeCodeCamp challenge for building a URL shortener service. It uses Node.js, Express, and MongoDB (via Mongoose) to provide a simple web API for shortening URLs. The application includes additional logic and packages to meet challenge requirements and all tests have been passed.
- Shorten long URLs to concise short links
- Store and retrieve URLs using MongoDB with Mongoose
- RESTful API endpoints
- Fully passes FreeCodeCamp test suite
- Node.js (v14 or later)
- npm
- MongoDB (local or Atlas)
-
Clone the repository:
git clone https://github.com/Thedevelop3r/url-shortner.git cd url-shortner -
Install dependencies:
npm install
-
Set up environment variables:
Create a
.envfile in the root directory and add your MongoDB URI:MONGO_URI=your_mongodb_connection_string PORT=3000 -
Start the application:
npm start
The server will run on
http://localhost:3000by default.
-
POST
/api/shorturl- Request Body:
{ "url": "https://example.com" } - Response:
{ "original_url": "https://example.com", "short_url": 1 }
- Request Body:
-
GET
/api/shorturl/:short_url- Redirects to the original URL corresponding to the provided short URL code.
- JavaScript (Node.js, Express)
- MongoDB & Mongoose
- CSS (for any frontend)
- Shell scripts (for automation tasks)
This project is open-source and available under the MIT License.