Long URLs aren't easy to email, tweet, or otherwise share. This application takes long urls and shortens them.
- Clone this repo onto your local machine using
git clone git@github.com:itchonib/url-shortener.git
and open it - Ensure you are in the root folder (url-shortener)
- Run the command
npm run install:all
to install all client and server-side dependicies - Create and .env file in the root of your directory. Make sure your .env file has the below set up (the MongoDB connection string has been emailed). Reminder that if you change the
PORT
, please updateBASE_URL
and the proxy value in the package.json of the client:
MONGODB_URL=
PORT=8080
BASE_URL=http://localhost:8080
- Run the project with
npm run dev
to run both the client and the server
- Any user visiting the page can use the site
- Design rough plan for FE design and set up database
- Set up API using Express and add route tests
- Build out basic FE component layout and styles
- Add functionality to components and unit + integration tests
- Review and refactor and make it better
- It can be anticipated that there can be millions of millions of links stored in the DB. As such, Mongo was used for its scalability. Moreover, there is no need to have relationships between tables/documents, so a relational database is not necessary.
- Adding tests did require more work/time, however it will reduce time on future refactors and addition new features
- It would take some more time to build an inhouse id generator and robust url validator so third party packages were used instead
- A cache layer was added to reduce load on the DB, however, for ease of running the project, it was kept in a separate branch. If you would like to run the project with the cache layer, please follow the instructions in the last section.
For packages used for testing please see the testing section.
The front end was built with react components and sass files. Apart from the built in packages that come with create-react-app, the following packages were used:
axios
was used to conduct HTTP requestsvalid-url
was used to validate format of URLsreact-router-dom
v6 was used to set up routes on the front end
MongoDB was utilized as the database for this application.
The server side was built in Node.js
with Express
. Mongoose
was used as the ORM. Along with standard packages like dotenv
, nodemon
, and cors
, more notable packages include:
hashids
was used to generate the "short" id used in the shortened URL.mongoose-sequence
was used to assign a unique counter number to each url document. The counter was used as part of the creation of the short id to ensure that each id generated was unique- Similar to the front end,
valid-url
was used on the back end to validate format of URLs Concurrently
was used to allow multiple commands simultaneously
- Server Side:
- Client Side:
React Testing Library
was used to created unit tests for specific components andCypress
was used for intergration tests. To run unit tests from the root folder pleasecd client && npm test
. To run cypress integration tests, in the root directory runnpm run cypress
.- Note please be aware there will be a deprecation warning when running cypress due to the
"nodeVersion": "bundled"
in the cypress.json. If you are using node version >=17, please do not remove that line, it is currently the only work around for a current cypress bug (reference)
- I would like to add a feature so a user can see previous links they have created without an account
- I would like to add a flo/feature where users can create an account to save their links and track how many times their link has been clicked
- I would like to add additional styles and designs to the client
- I would like to deploy the app
- I would like to add continous integration by running cypress tests with github actions
- I would like to build in house code to generate the short URL id
In order to create a cache layer and use react testing library for the first time, the following resources were used:
- This article by Subhra Paladhi was a fantastic guide. It provided boiler plate code to set up the cache layer that was used in the project.
- This article by Robin Wieruch was a wonderful resource as it provided detailed guidance on how to set up tests using react testing library
Documentation for all packages listed above were also consulted often for best practices.
This project utilized redis and util to set up the cache layer.
- If you do not have redis installed, please install it by running
brew install redis
. Start redis with the following command:brew services start redis
- Make sure to clone the repo with
git clone
and install all dependencies usingnpm run install:all
- In addtion to the what was listed above in the set up section, please add the following to your .env file
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
- Checkout into the feature branch with
git checkout feature/add-redis-cache
- Once in the branch, please run
npm i
again to install redis and utils. - Please run
npm run dev
to start the project. - Once you are done with the app, do not forget to run
brew services stop redis
to turn off the redis server.