- Install packages:
npm i
- Export environment variables as below (example):
EXPORT MONGODB=mongodb://root:root@localhost:27017/urlshortener?authSource=admin - Then run the Project:
npm run start
Simply run the project with docker-compose:
docker-compose up -dIt will build the project first, then runs it.
- I tried to control the user inputs as much as I could with
Joipackage - I added docker support,
Dockerfileanddocker-compose.ymlfor easier usage, Alsomongodbandredissetup included insidedocker-compose - I used
prettierwith.prettierrcconfig to maintain a single code style across all files in project. - I used
eslintto prevent future bugs, performance and code style problems. - I did my best to follow best practices, Like
DRY,KISS,YAGNI. - Used middlewares for input validation in order to prevent code repetition.
- Implemented an
errorsservice, which is a proxy to throw errors in a stylish was, also has http status code in it. - Added a
Postmancollection file indocsfolder for easier testing. - Of course I can give the same short url slug for same url again, but I thought, Maybe we want to track each short url separately, or maybe two deferent users want a same url be shortened.
- Add more logs with a better log package like
winstonfor implement log to file and file rotation, etc... - Add more tests, for every controller, db methods, etc...
Total time I spent on this task: 2h 30m