Snipr is a secure, user-based URL shortener built with Node.js, Express, MongoDB, and JWT authentication. It allows users to register, log in, shorten URLs, and manage their own links securely.
- User Registration & Login: Secure authentication with JWT tokens.
- Shorten URLs: Authenticated users can shorten any valid URL.
- No Duplicate Short URLs: Prevents duplicate short URLs for the same original URL per user.
- User-Specific URLs: Each user can view only their own shortened URLs.
- Public Redirect: Anyone can use a short URL to be redirected to the original URL.
- Click Tracking: Each redirect increments a click counter.
POST /api/auth/register— Register a new user. Returns JWT token and user name.POST /api/auth/login— Log in. Returns JWT token and user name.
POST /api/snipr— Shorten a URL (requires JWT inAuthorization: Bearer <token>header).- Request body:
{ "originalUrl": "https://example.com" } - Response:
{ message, shortUrl }
- Request body:
GET /api/urls— Get all URLs created by the authenticated user (requires JWT).
GET /api/:shortUrl— Redirects to the original URL for the given short code.
- Register a user via
/api/auth/register. - Login to get a JWT token.
- Use the token to shorten URLs and view your URLs.
- Share the short URL (e.g.,
http://localhost:3000/api/abc123) — anyone can use it to be redirected.
Create a .env file in the root directory:
MONGODB_URI=mongodb://localhost:27017/snipr
JWT_SECRET=your_jwt_secret_key
PORT=3000
- Install dependencies:
npm install - Start the server:
npm run dev
- Node.js
- Express.js
- MongoDB & Mongoose
- JWT (jsonwebtoken)
- bcrypt
- shortid