Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A RESTful URL shortening service built with Express and MongoDB (Mongoose).

Project structure

src/
  config/        Environment loading + validation, DB connection
  models/        Mongoose schemas
  services/      Business logic (talks to models, throws ApiError)
  controllers/   Thin HTTP layer (parses req, calls service, shapes res)
  routes/        Express routers, wired to controllers + middleware
  middlewares/   Validation, request logging, 404, centralized error handler
  utils/         ApiError, ApiResponse, asyncHandler, logger, short code generator
  app.js         Express app assembly (no listening)
  server.js      Entry point: connects DB, then starts the HTTP server

app.js and server.js are split on purpose: app.js can be imported by integration tests (supertest, etc.) without opening a real port or DB connection.

Setup

npm install
cp .env.example .env   # then fill in MONGO_DB_CONN_STRING
npm run dev             # nodemon, for local development
npm start                # plain node, for production

API

Base path: /api/v1/urls

Method Path Description
POST /api/v1/urls Create a short URL. Body: { "url": "https://..." }
GET /api/v1/urls/:shortCode Get metadata for a short code
PUT /api/v1/urls/:shortCode Update the long URL behind a code
DELETE /api/v1/urls/:shortCode Delete a short URL
GET /:shortCode Redirect (302) to the long URL, increments accessCount

All responses use a consistent envelope:

{ "success": true, "message": "Short URL created", "data": { ... } }

Errors:

{ "success": false, "message": "No URL found for short code 'abc123'" }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages