Free and open‑source URL shortener focused on simplicity. Create short links, share them, and get instant redirects.
- Clean UI with Tailwind CSS
- Create custom short slugs for your links
- Instant redirect via dynamic route
app/[url]/page.js
- API route to create short links:
POST /api/generate
- MongoDB persistence
- Next.js App Router
- React 19
- MongoDB (official Node driver)
- Tailwind CSS v4
Prerequisites:
- Node.js 18+ (LTS recommended)
- A MongoDB connection string (Atlas or local)
- Clone and install
git clone <your-repo-url> bitlinks
cd bitlinks
npm install
- Configure environment
Create a .env.local
file in the project root:
MONGODB_URI="your-mongodb-connection-string"
NEXT_PUBLIC_HOST="http://localhost:3000"
Notes:
MONGODB_URI
is required bylib/mongodb.js
.NEXT_PUBLIC_HOST
is used to show the full generated short link in the UI.
- Run the dev server
npm run dev
Open http://localhost:3000
in your browser.
npm run build
npm run start
app/
page.js # Landing page
shorten/page.js # UI to create short links
[url]/page.js # Dynamic redirect route
api/generate/route.js # API: create short links
lib/
mongodb.js # MongoDB client
public/
team.png # Hero image
Create a new short link.
Request body:
{
"url": "https://example.com/very/long/link",
"shorturl": "my-custom-slug"
}
Response (success):
{
"success": true,
"error": false,
"message": "URL generated successfully"
}
If shorturl
already exists, the API responds with:
{
"success": false,
"error": true,
"message": "Short URL already exists"
}
- Visiting
http://<host>/<shorturl>
hitsapp/[url]/page.js
. - The page looks up the slug in MongoDB and issues a server redirect to the original URL.
- If not found, it redirects back to
NEXT_PUBLIC_HOST
.
You can deploy anywhere that supports Next.js. Common options:
- Vercel: add the environment variables (
MONGODB_URI
,NEXT_PUBLIC_HOST
) in the project settings. Thenvercel --prod
or connect your GitHub repo. - Node server: build with
npm run build
and run withnpm run start
. Ensure env vars are set on the host.
Contributions are welcome! Feel free to open issues and pull requests.
- Fork the repo
- Create a feature branch:
git checkout -b feat/your-feature
- Commit changes:
git commit -m "feat: add awesome thing"
- Push:
git push origin feat/your-feature
- Open a PR
MIT License. See LICENSE
file if present. If not, you may license this project under MIT with the following header in your contributions:
MIT License © Your Name