REST API using MongoDB and Express
I originally made this as a simple url shortener API for a back-end project in 2018. After completing the API, I built a simple front-end to interact with it. I've made a couple edits since then to modernize some outdated libraries and code.
- Automatically redirect short URL's to an original URL
- Express.js and MongoDB REST api
- MVC architecture
- Mongoose.js ODM
- Modern javascript features such as ES modules, fetch API, and top-level await
- Simple frontend app to interact with REST api
Enter the URL you wish to shorten:
Copy or visit the shortened URL returned:
Use /api/new/<url>
endpoint to create a new short url. Example:
https://url.iabrahamson.com/api/new/github.com
https://url.iabrahamson.com/api/new/https://github.com/IsaacAbrahamson/URL-Shortener/
{
"originalUrl": "github.com",
"shortUrl": "/57e2a"
}
{
"originalUrl": "github.com/IsaacAbrahamson/URL-Shortener",
"shortUrl": "/70016"
}
Use /api/all
to view entire urls
collection.
Visit url.iabrahamson.com/<shorturl>
to be redirected to the original website.
You will need Node.js and MongoDB installed locally to run this project.
Install all dependencies:
npm install
Add a .env
file with the location to a MongoDB database:
# Local MongoDB Database
DB_URL="mongodb://localhost/urls"
# MongoDB Atlas Database
DB_URL="mongodb+srv://urluser:urlpassword@cluster123.mongodb.net/?retryWrites=true&w=majority"
Start:
npm start