A modern, feature-rich URL shortening service built with Node.js, Express, MySQL, and Tailwind CSS.
git clone https://github.com/yourusername/url-shortener.git
cd url-shortener
npm install
# or
yarn install
Create a MySQL database and run the schema file:
mysql -u your_username -p your_database_name < src/models/schema.sql
Create a .env
file in the root directory:
DB_HOST=localhost
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=url_shortener_db
PORT=5000
BASE_URL=http://localhost:5000
npm start
# or
yarn start
The application will be available at http://localhost:5000
The dashboard provides basic analytics for each URL:
/api/urls/shorten
{ "originalUrl": "https://example.com", "customCode": "example" }
/api/urls/dashboard
page
(default: 1), limit
(default: 10)/api/urls/:id
/api/urls/delete/:id
(alternative for browsers)/:shortCode
url-shortener/
├── public/ # Static assets
│ ├── css/ # CSS files
│ ├── js/ # JavaScript files
│ └── images/ # Image files
├── src/
│ ├── config/ # Configuration files
│ │ └── db.js # Database connection
│ ├── controllers/ # Route controllers
│ │ └── urlController.js
│ ├── models/ # Database models
│ │ ├── Url.js # URL model
│ │ └── schema.sql # Database schema
│ ├── routes/ # Route definitions
│ │ ├── index.js # Main routes
│ │ └── urlRoutes.js # URL-related routes
│ ├── views/ # EJS templates
│ │ ├── layouts/ # Layout templates
│ │ ├── dashboard.ejs # Dashboard page
│ │ ├── index.ejs # Home page
│ │ └── error.ejs # Error page
│ └── app.js # Application entry point
├── .env # Environment variables
├── package.json # Dependencies and scripts
└── README.md # Project documentation
The application uses Tailwind CSS for styling. You can customize the colors in the tailwind.config.js
file:
module.exports = {
theme: {
extend: {
colors: {
primary: {
// Customize your color palette
}
}
}
}
}
The EJS templates are located in the src/views
directory. You can modify them to change the appearance of the application.
git checkout -b feature-name
git commit -m 'Add some feature'
git push origin feature-name
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name - your.email@example.com
Project Link: https://github.com/yourusername/url-shortener