- 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 -d
It will build the project first, then runs it.
- I tried to control the user inputs as much as I could with
Joi
package - I added docker support,
Dockerfile
anddocker-compose.yml
for easier usage, Alsomongodb
andredis
setup included insidedocker-compose
- I used
prettier
with.prettierrc
config to maintain a single code style across all files in project. - I used
eslint
to 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
errors
service, which is a proxy to throw errors in a stylish was, also has http status code in it. - Added a
Postman
collection file indocs
folder 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
winston
for 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