qURL is a simple URL shortening service built with Node.js, Express, and Prisma. It provides an API to shorten URLs, supports custom aliases, and redirects users to the original URLs. It also integrates Prisma as the database ORM for managing shortened URLs.
- Shorten URLs with randomly generated or custom paths.
- Redirect to original URLs using the shortened URL.
- Block access to certain domains.
- JSON-based status API for counting shortened URLs.
- Swagger documentation for easy API exploration.
- Node.js: Server-side JavaScript runtime.
- Express.js: Web framework for Node.js.
- Prisma: ORM for managing database models and queries.
- SQLite/PostgreSQL/MySQL: Database (You can use any database supported by Prisma).
- Swagger UI: API documentation interface.
- Node.js (v14.x or higher)
- npm or yarn
- SQLite, PostgreSQL, MySQL, or any other Prisma-supported database
- Prisma (installed via npm)
-
Clone the repository:
git clone https://github.com/caliph91/qURL.git cd qURL
-
Install dependencies:
npm install
-
Set up the
.env
file:Copy the example
.env
file and set your database credentials in the new.env
file.cp example.env .env
Example
.env
for SQLite:DATABASE_URL="file:./dev.db"
Example
.env
for PostgreSQL:DATABASE_URL="postgresql://user:password@localhost:5432/mydatabase?schema=public"
-
Migrate the database schema:
npx prisma migrate dev --name init
-
Generate Prisma client:
npx prisma generate
-
Run the development server:
npm start
The application will be running at
http://localhost:8877
.
- GET
/api/create
- Query Parameters:
url
(required): The URL you want to shorten.alias
(optional): A custom alias for the shortened URL.
Example:
curl "http://localhost:8877/api/create?url=https://example.com"
Response:
{
"success": true,
"error": null,
"response": {
"url": "https://example.com",
"short": "http://localhost:8877/abcd1234"
}
}
- GET
/api/status
Example:
curl "http://localhost:8877/api/status"
Response:
{
"shorten": 100
}
- GET
/:path
Use the shortened path (/abcd1234
) to redirect to the original URL.
Example:
curl -L "http://localhost:8877/abcd1234"
- If a URL is blocked or if a DNS error occurs, the user is redirected to a
/blocked
page.
- Access the API documentation and test the API with the Swagger UI at:
http://localhost:8877/api-docs
qURL uses Prisma as an ORM. You can easily switch between databases like SQLite, PostgreSQL, or MySQL by changing the DATABASE_URL
in your .env
file and running the migrations.
If you modify the schema, you can apply changes by running:
npx prisma migrate dev --name your_migration_name
To visually inspect and manage your database, use Prisma Studio:
npx prisma studio
To deploy the app to Heroku, follow these steps:
-
Set up the Prisma environment in Heroku by adding your
DATABASE_URL
as a config variable. -
Push your code to Heroku:
git push heroku master
-
Run migrations on the Heroku server:
heroku run npx prisma migrate deploy
The app can be deployed on any platform that supports Node.js and Prisma. Just make sure to configure the environment variables (DATABASE_URL
) correctly.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to open issues or pull requests if you'd like to contribute. Any feedback is appreciated!