A simple and efficient URL shortener application that allows users to shorten long URLs.
This URL shortener is a web application that allows users to convert long URLs into short links.
- | Name | Link |
---|---|---|
Language | Node.js | |
Server | Exress.js | |
Database | SQLite | |
ORM | Sequelize | |
View Engine | EJS |
Note: No need to install SQLite on your local environment, SQLite npm package will do the job.
- Open the terminal and clone the repository:
git clone https://github.com/mmedoo/url-shortener.git
- Go to the app directory
cd url-shortener
- Install dependencies
npm install
- Run the server
npm start
Once the server runs, terminal should log:
Server is listening on http://localhost:1234
- Open your browser and go to
http://localhost:1234
. - Enter the long URL you want to shorten.
- Click the "Shorten" button to get the short URL.
- Click on displayed URL to copy.
- Paste it in your browser.
Congrats 🌟, you're redirected to your super long URL.
- Creates a new key, if doesn't exist, for
{desired_url}
. - Responds with the key.
- Requests the URL corresponding to
{key}
. - Responds with a redirectng page to corresponding URL.
The application can be configured using environment variables. Here are the available options:
PORT
: The port on which the application will run (default: 1234).FORCE_DROP
: Boolean value to determine wether thelinks
database table is forcably dropped everytime the app initializes connection with the database (this determines if the data will be saved after closing the app) (default: false).
- Create the .env File: Open the terminal in app folder and run command:
touch .env
- Open the .env File for Editing: You can use any text editor of your choice, here is a way through the terminal:
nano .env
- Add environment variables and set them as you like:
PORT=1234
FORCE_DROP=false
- Create the .env File: Open the terminal in app folder and run command:
echo.>.env
- Open the .env File for Editing: You can use any text editor of your choice to open and edit the .env file. Run this command to use notepad:
notepad .env
- Add environment variables and set them as you like:
PORT=1234
FORCE_DROP=false