This service accepts a URL as a parameter and will check whether it follows the valid https://www.google.com format. If the URL is valid, it will return both the original URL and shortened URL in the JSON response. If it is not valid, the JSON response will contain an error instead. When you visit that shortened URL, it will redirect you to the original link.
You can test it at https://url-shortener-microsrvc.herokuapp.com
A Full Stack Javascript application built using MongoDB, Node.js and Express. An API Project for FreeCodeCamp.
Pass the URL to path https://url-shortener-microsrvc.herokuapp.com/new/[URL] as below:
https://url-shortener-microsrvc.herokuapp.com/new/https://www.github.com
https://url-shortener-microsrvc.herokuapp.com/new/www.github.com
{
original_url: "https://www.github.com",
shortened_url: "https://url-shortener-microsrvc.herokuapp.com/29183"
}
Visiting the shortened URL: https://url-shortener-microsrvc.herokuapp.com/29183 will redirect to: https://www.github.com
In order to run this project locally, you should have the following installed:
-
Fork this repo
-
Clone the fork
-
Install Dependencies:
$ npm install
-
Run your MongoDB server:
$ mongod --port 27017 --dbpath=./data
Note: Your mongoDB is now running at: mongodb://localhost:27017/<your_database_name>
-
Add a .env file to your project's root directory and set MONGO_CONNECTION_STRING to mongodb://localhost:27017/<your_database_name>
MONGO_CONNECTION_STRING=mongodb://localhost:27017/<your_database_name>
-
Start the Server:
$ node app.js
-
Visit http://localhost:3000/
Enjoy! 💙