A simple URL shortener built using Node.js, Express, and REST API, following the MVC architecture for efficient URL management.
- User authentication (Admin & Regular users)
- URL shortening functionality
- Analytics for shortened URLs
- Role-based access control
- Secure password hashing using bcrypt
- JWT-based authentication
- MongoDB for data storage
- Clone the repository:
git clone https://github.com/siddheshrm/node-url-shortner.git
- Navigate to the project directory:
cd node-url-shortner
- Install dependencies:
npm install
- Create a
.env
file in the root directory and configure environment variables:MONGODB_URI=mongodb://127.0.0.1:27017/mongo-db-name SECRET_KEY=your_secret_key [email protected]
-
Start the server:
npm start
Runs the application using Nodemon for automatic restarts.
-
Make an admin user:
npm run make-admin
Runs
makeAdmin.js
to assign admin privileges to a user in the database. Make sure to modify the script with the correct user email before running it.
url-shortner/
│── controllers/ # Controller functions
│── models/ # Mongoose models
│── routes/ # Express routes
│── views/ # EJS templates
│── public/ # Static assets (CSS)
│── .env # Environment variables
│── index.js # Main application entry point
│── API Documentation # Dependencies and scripts
│── package.json # Dependencies and scripts
- Run
npm start
to start the server. - Open
http://localhost:3000/
to access the application.
For detailed API endpoints and request-response examples, refer to API Documentation.
You can learn more about me and my other projects on my personal portfolio website.