A simple, robust, and scalable URL shortener API built with Node.js and Express. It converts long URLs into short, easy-to-share links and tracks the number of clicks for each link. The backend is powered by a persistent, cloud-based SQLite database using Turso.
The API is live and ready to use. The base URL for all requests is:
https://landing-in.onrender.com
- Shorten URLs: Quickly generate a unique, 8-character short ID for any valid URL.
- Click Tracking: Automatically counts every time a short link is used.
- Fast Redirects: Instantly redirects users from the short link to the original destination.
- Persistent Storage: Uses a Turso cloud database to ensure data is never lost.
- CORS Enabled: Can be called directly from any web application.
- Backend: Node.js, Express.js
- Database: Turso (libSQL/SQLite)
- Deployment: Render
- ID Generation: Node.js
crypto
module
Creates a new short link for a given long URL.
- Method:
POST
- Endpoint:
/generateshorturl
The body must be a JSON object with a single longUrl
key.
Field | Type | Description | Required |
---|---|---|---|
longUrl |
String | The original URL to shorten. | Yes |
cURL:
curl -X POST https://landing-in.onrender.com/generateshorturl \
-H "Content-Type: application/json" \
-d '{"longUrl": "https://developers.googleblog.com/en/veo-3-and-veo-3-fast-new-pricing-new-configurations-and-better-resolution/"}'
JavaScript Fetch:
const response = await fetch('https://landing-in.onrender.com/generateshorturl', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ longUrl: 'https://developers.googleblog.com/en/veo-3-and-veo-3-fast-new-pricing-new-configurations-and-better-resolution/' })
});
const data = await response.json();
console.log(data);
{
"longUrl": "https://developers.googleblog.com/en/veo-3-and-veo-3-fast-new-pricing-new-configurations-and-better-resolution/",
"shortUrl": "http://landing-in.onrender.com/d27bbc8b"
}
Redirects the user to the original long URL and increments the click count.
- Method:
GET
- Endpoint:
/:shortId
Simply navigate to the short URL in a web browser.
Example:
Visiting http://landing-in.onrender.com/d27bbc8b
in your browser will redirect you to https://developers.googleblog.com/en/veo-3-and-veo-3-fast-new-pricing-new-configurations-and-better-resolution/
.
Retrieves the total click count for a specific short URL.
- Method:
GET
- Endpoint:
/count/:shortId
cURL:
curl http://landing-in.onrender.com/count/d27bbc8b
Browser:
Visit http://landing-in.onrender.com/count/d27bbc8b
in your browser.
{
"shortId": "1a2b3c4d",
"clicks": 15
}
Follow these steps to run the project on your own machine.
Clone the repository and install the necessary npm packages.
git clone https://github.com/elvishpatel/landing-api.git
cd landing-api
npm install
Create a free database on Turso and get your credentials.
# Log in to Turso
turso auth login
# Create a new database
turso db create your-database-name
# Get the URL
turso db show your-database-name --url
# Get an auth token
turso db tokens create your-database-name
Create a file named .env
in the root of your project. Copy the contents of .env.example
(if present) or add your Turso credentials to it.
.env file:
TURSO_DATABASE_URL="libsql://your-db-name-username.turso.io"
TURSO_AUTH_TOKEN="your-long-auth-token"
Run the setup script once to create the urls
table in your Turso database.
node setup-db.js
Start the local development server.
node index.js
The API will now be running at http://localhost:3000
.
This project is licensed under the MIT License. See the LICENSE
file for details.
Developed with ❤ by Elvish Patel