A scalable backend service for generating and managing short URLs, built using Node.js, Express, PostgreSQL, and Drizzle ORM.
- User Authentication (JWT-based)
- Password hashing with salt (crypto)
- Create short URLs using nanoid
- Redirect short URLs to original links
- PostgreSQL relational database
- Drizzle ORM integration
- Dockerized setup
- Node.js
- Express.js
- PostgreSQL
- Drizzle ORM
- JWT Authentication
- Zod (validation)
- Docker
.
├── controllers/
├── models/
├── database/
├── utils/
├── docker-compose.yml
├── Dockerfile
├── server.js
└── README.md
git clone https://github.com/your-username/url-shortener-backend.git
cd url-shortener-backend
npm install
Create a .env file:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
JWT_SECRET=your_secret_key
PORT=3000
docker compose up -d
npm start
- POST
/user/signin→ Register user - POST
/user/login→ Login user - POST
/user/codes→ Get all codes of user of all urls
- POST
/shorten→ Create short URL (Auth required) - GET
/r/:shortCode→ Redirect to original URL
- id (UUID)
- password
- salt
- id (UUID)
- user_id (FK)
- short_code
- target_url
Run full backend with PostgreSQL:
docker compose up --build
Sandesh Pawar