https://github.com/sahil-4/url-shortener-backend
URL Shortener backend
https://github.com/sahil-4/url-shortener-backend
email-verification express expressjs jwt mongoose node nodemailer otp-generator otp-verification url-shortener url-shortener-microservice
Last synced: about 2 months ago
JSON representation
URL Shortener backend
- Host: GitHub
- URL: https://github.com/sahil-4/url-shortener-backend
- Owner: Sahil-4
- Created: 2024-02-02T14:54:59.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-20T06:36:32.000Z (about 1 year ago)
- Last Synced: 2025-02-14T16:59:59.101Z (4 months ago)
- Topics: email-verification, express, expressjs, jwt, mongoose, node, nodemailer, otp-generator, otp-verification, url-shortener, url-shortener-microservice
- Language: JavaScript
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL Shortener Backend
This is backend part of URL Shortener application created using MERN.
We can create a short URL for a long URL and can use short url to reach to the original long URL.This repository contains code of backed part you can find the github repo of frontend here : [Sahil-4/url-shortener](https://github.com/Sahil-4/url-shortener)
You can find the frontned live here : [https://a-short.netlify.app/](https://a-short.netlify.app/)
and backend here : [https://a-short.onrender.com/](https://a-short.onrender.com/)### Features
- **custom otp based email verification** : implemented custom logic for email verification while creating a new account.
- **custom base 62 hash generator** : implemented custom function to generate unique hash of 6 length to create short url.
- **express** : used to create an http/https server.
- **mongoose** : to connect to mongodb database and handle db operations.
- **cors** : to handle communication between cross origins.
- **dotenv** : to keep keys secure.
- **jsonwebtoken** : to generate access token.
- **bcrypt** : to hash password.
- **nodemailer** : to send otp verification email.### API Endpoints
- **POST /api/v1/auth/get-otp**: Request to send an OTP for email verification.
- **POST /api/v1/auth/signup**: User registration endpoint.
- **POST /api/v1/auth/login**: User login endpoint.
- **GET /api/v1/auth/deactivate**: Endpoint to delete the user account.
- **GET /api/v1/url/get**: Retrieve all URLs generated by a user.
- **POST /api/v1/url/new**: Create a new short URL.
- **POST /api/v1/url/delete**: Delete a URL.### API Documentation
- **Request OTP**
`POST : /api/v1/auth/get-otp ````
body : {
username : "username",
email : "[email protected]",
}
``````
response : {
success: true,
message: "otp send successfully",
data: null
}
```- **Create a new user**
`POST : /api/v1/auth/signup````
body : {
username : "username",
email : "[email protected]",
password: "password",
otp: "111111",
}
``````
response : {
success: true,
message: "user created successfully",
data : {
_id: user_id,
username,
email: user_email,
token: access_token,
};
}
```- **login**
`POST : /api/v1/auth/login````
body : {
email : "[email protected]",
password: "password",
}
``````
response : {
success: true,
message: "login successful",
data : {
_id: user_id,
username,
email: user_email,
token: access_token,
};
}
```- **delete a user**
`GET : /api/v1/auth/deactivate````
response : {
success: true,
message: "account deleted successfully",
}
```- **Get URLs generated by current logged in user**
`GET : /api/v1/url/get````
response : {
success: true,
message: "urls fetched successfully",
data: [Array of { URL Objects }],
}
```- **create a new short URL**
`POST : /api/v1/url/new````
body : {
original_url : "https://some.valid.url.com/path",
}
``````
response : {
success: true,
message: "url created successfully",
data: { URL Object },
}
```- **Delete a URL**
`POST : /api/v1/url/delete````
body : {
short_url : "https://a-short.onrender.com/HASH",
}
``````
response : {
success: true,
message: "successfully deleted the url",
data: { Deleted URL Object }
}
```- **Redirect to original URL from short URL**
`GET : /HASH````
RESPONSE : 301, REDIRECT to Original Long URL
```### Installation and Setup
**clone the repository**
`git clone [email protected]:Sahil-4/url-shortener-backend.git`
**Install required packages**
`npm install`
**Add env variables**
Create dot env file (.env) in the root directory and add all variables given in .env.example file with proper values in .env file
**Start the app**
`npm run start`
**to test the application properly make sure to check out frontend part [here](https://github.com/Sahil-4/url-shortener)**