A URL shortener made using NodeJS, MongoDB, and Vercel serverless function. This project also includes a serverless API. With the help of this API, we can Integrate the URL shortener with basic static (HTML/CSS/JS ) websites. This website can also serve as a Progressive Web Application (PWA) where you can install this website as a normal Application on your PC or Phone.
Client: HTML, SCSS, JS, Bootstrap, Materialize
Server: Node,TS, MongDB, Vercel Serveless function.
- NodeJS
- MongoDB (Atlas)
- Vercel CLI
To get this poject running, firstly install vercel CLI on your PC with the following command.
npm i -g vercel
Secondly, goto MongoDB and configure a MongoDB Atlas cluter running, Setup the MongoDB clutter and copy the URI for NodeJS application.
After the MongoDB setup is done clone this project and install the packages.
git clone https://github.com/adithyapaib/lenk.cf
cd lenk.cf
npm i
create .env file in the root folder and create variable DB and paste your MongoDB URI
DB = YOUR_URI_WITHOUT_QUOTES
After everthing is installed to locally deploy this project type
vercel dev
Login with your Vercel account and your all set for Local Deployment on.
localhost:3000
For web Deployment on Vercel use
vercel deploy
localhost:300/api/
Type | File | Description |
---|---|---|
string |
index.js | Displays info about API |
localhost:300/${shortId}
Parameter | File | Description |
---|---|---|
ShortId |
redirect.js |
Required ID of item to redirect |
localhost:300/p/
Parameter | File | Description |
---|---|---|
url |
p.js |
Required url of main URL. Responds with a random shortID. |
- Make sure you are using encodeURIComponent to send request to /p/
localhost:300/all
Parameter | File | Description |
---|---|---|
all.js |
Displays all the URL's in the database. |
localhost:300/custom/<shortIDLength>_<shortId><original_url>
Parameter | File | Description |
---|---|---|
<shortIDLength>_<shortId><original_url> |
custom.js |
Checks if the shortID is taken, return true if shortID is unique else return false if there exits any conflict shortID |
Parameter | File | Example |
---|---|---|
<shortIDLength>_<shortId><original_url> |
custom.js |
http://localhost:3000/3_adihttps://github.com/adithyapaib |
localhost:300/404
Parameter | File | Description |
---|---|---|
/404 |
404.html |
404 Page |
To run this project, you will need to add the following environment variables to your .env file
DB = YOUR_MONGOURI
Other domains to this project.
- Dont forget to 🙋🏼♂️Follow me on Github and Star⭐ this Repo