LinkSnap is a RESTful URL shortener backend built using Node.js, Express.js, MongoDB, and Mongoose. It converts long URLs into short links, redirects users to the original URL, and provides basic click analytics.
- Shorten long URLs into unique short links
- Generate unique short codes
- Redirect short URLs to original URLs
- Track number of clicks
- View analytics for shortened URLs
- Prevent duplicate URL entries
- Validate URLs before shortening
- Retrieve all shortened URLs
- Global 404 route handling
- MongoDB database integration
- Node.js - JavaScript runtime
- Express.js - Backend web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB ODM
- JavaScript - Programming language
- Postman - API testing
- Nodemon - Development server
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/urls/shorten |
Create a short URL |
| GET | /api/urls/:shortCode |
Redirect to original URL |
| GET | /api/urls/stats/:shortCode |
Get URL click analytics |
| GET | /api/urls |
Get all shortened URLs |
POST /api/urls/shorten{
"originalUrl": "https://www.google.com"
}{
"originalUrl": "https://www.google.com",
"shortUrl": "http://localhost:5000/api/urls/abc123",
"shortCode": "abc123"
}GET /api/urls/stats/abc123Example response:
{
"originalUrl": "https://www.google.com",
"shortCode": "abc123",
"clicks": 5,
"createdAt": "2026-07-25T00:00:00.000Z"
}Clone the repository:
git clone <your-repository-url>
cd linksnap-url-shortenerInstall dependencies:
npm installCreate a .env file in the project root:
PORT=5000
MONGO_URI=your_mongodb_connection_stringStart the development server:
npm run devServer will run on:
http://localhost:5000
- Client sends a long URL to the shortening API.
- LinkSnap validates the URL.
- The database is checked for an existing URL.
- A unique short code is generated for new URLs.
- The URL and short code are stored in MongoDB.
- Opening the short URL redirects the user to the original URL.
- Each redirect increments the click counter.
- Analytics can be retrieved using the stats endpoint.
Sensitive configuration is stored inside .env and excluded from Git using .gitignore.
node_modules/
.envAditi Rathi
Backend Developer