Skip to content

pecampelo/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

Greetings, traveler. This is a WIP project (Work in Progress Project) of a URL shortener made out to shorten and redirect a user towards an original previously typed-in page. It was primarily programmed to be a microservice component, and it all started from a technical challenge for a job interview.

Wanna see it? >> https://url-shortener1234567.herokuapp.com/encurtador

Want to see its documentation? There is a little story there.

https://documenter.getpostman.com/view/15716598/TzRVdRAp

Technologies proposed

  • TypeScript (compiled to Javascript).
  • NodeJS;
  • Express + Jest;
  • PostgreSQL through pg;
  • Postman;
  • Docker;

How to Install

npm install

There are two ways you can run this server:

    1. npm run postinstall followed by npm start for production purposes.
    1. npm run dev for development and continuous debugging.

My Development Steps

  1. Install and save these packages for development purposes:
  • ts-node-dev for simultaneous alterations;
  • config + @types/config;
  • express + @types/express;
  • jest + ts-jest + @types/jest;
  • typescript + @types/node;
  • ejs for user interface;
  • body-parser to store data as JSON;
  • pg (postgres module);
  1. Set up an Express app for the server.

  2. Create a test file that will at first fail the test, as there is no code written. After, a mock test in order to test importing of node_modules from the app to the test file will be done.

  3. If passed, all possibilities that should be accounted for in a test will be written down so there is Test-Driven Development;

  4. Create a static front-end file with forms.

  5. Write HTTP request methods and create shortener function.

  6. Deploy to Heroku.

  7. Connect to a database in order to save Urls.

  8. Use Postman to test methods and save collection to package.

  9. Redirect user to longUrl page.

  10. Write functions that suffice the tests passing.

  11. Package using Dockerfile.

How does it work?

  1. User ask for the server to shorten a link. That does 2 things:
  1. Then, the server creates the shortened URL called as a "newUrl" attribute in a JSON file with an index number and stored in the database.

  2. Server returns the shortUrl to the user.

  3. When the user makes use of the shortened URL, the user is by consequence issuing a GET request for the original URL as well, which is saved in the database. It can either redirect the user towards the original URL, or return a HTTP 404 response.

About

A URL shortener made to be available as a component for any web application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published