Node.js + Next.js Backend

URL shortener backend starter, ready to run locally.

This project is configured with Next.js route handlers, SQLite, Zod validation, and Nano ID short-code generation. The local database initializes itself automatically so you can start building on top of the API immediately.

POST /api/shorten and GET /:shortCode

Included dependencies

  • next, react, react-dom for the app runtime
  • better-sqlite3 for local persistence
  • zod for request validation
  • nanoid for unique short codes

Available API routes

  • POST /api/shorten creates a short link
  • GET /api/links lists saved links
  • GET /[shortCode] redirects and increments clicks

Example request

curl -X POST http://localhost:3000/api/shorten \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","customCode":"demo123"}'

Next steps

Start the dev server, create links through the API, and build your URL creation form or analytics UI on top of the routes already added.

npm run dev