A simple URL shortener built with Node.js, Express, PostgreSQL, and React.
- Shorten long URLs into unique short links.
- Store and retrieve URLs using PostgreSQL.
- Redirect short URLs to their original long URLs.
- Simple frontend to create and display shortened links.
- Backend: Node.js, Express.js, PostgreSQL
- Frontend: React.js
- Database: PostgreSQL
- Node.js installed
- PostgreSQL installed and running
- Create a PostgreSQL database:
CREATE DATABASE urlShortener;
- Update database credentials in
index.js
(backend file):const db = new db.Client({ user: "your_username", host: "localhost", database: "urlShortener", password: "your_password", port: 5432, });
- The table will be automatically created when the server starts.
- Install dependencies:
npm install express pg shortid cors
- Start the server:
node index.js
- Install dependencies:
npm install axios
- Add
LinkShortener
component in your React app.
- Endpoint:
POST /shorten
- Request Body:
{ "longUrl": "https://example.com" }
- Response:
{ "shortUrl": "abc123" }
- Endpoint:
GET /:shortUrl
- Example:
GET /abc123
→ Redirects tohttps://example.com
- Start PostgreSQL and ensure the database is running.
- Start the backend server.
- Run the frontend React app.
- Open the frontend in a browser and test URL shortening.
This project is open-source and available under the MIT License.
Developed by Naveen Kumar 🚀