This is a RESTfulAPI app by Nodejs (express framework)
- Anyone can register and login based on JWT.
- After login, you can access to Post/Put/Get/Delete your url.
- You can see analytic about your urls.
- Install lastest LTS version of NodeJs and MongoDb
- Open cmd from project root on your os (win - mac - linux) and run:
npm install
nodemon for run-watching mode development
npm i -g nodemon
because those are tools not a dependency for the project
jest
jest-cli
supertest
dotenv
artillery
cross-env
1- jest
- This package use for unit-test
2- supertest
- intergration-test
3- dotenv
- .env file for our Environment variables as we need
4- artillery
- test-stress (benchmark)
5- cross-env
- cross to different NODE_ENV=dev or prod or test
npm run start
npm run start-dev
docker-compose up
Or run only
node index.js
You can use Postman to communicate with API endpoints. You must import collection and environment files ((there are at the root of the project)) to your postman application.
After call Post request to Urls endpoint, you can get shorturlkey and test urlshortner redirection service in your browser:
http://localhost:5000/{{shorturlkey}}
I used config to manage some keys:
{
"name":"Url Shorter",
"db":"mongodb://localhost/UrlShorter_db",
"jwtPrivateKey": "12345",
"shorturlkeyCharacterCount":5
}
But I used Docker in Production mode and MongoDB Connection String must be like this:
"mongodb://mongo:27017/UrlShorter_db"
"mongo" is the name of MongoDB Container in docker-compose services config
You can run unit and integration tests with below command:
npm run test
You can run test-stress and get the report with below command:
npm run test-stress
It's the test-stress report:
All virtual users finished
Summary report @ 23:46:47(+0430) 2020-04-12
Scenarios launched: 2400
Scenarios completed: 2400
Requests completed: 7200
Mean response/sec: 119.13
Response time (msec):
min: 2.4
max: 52.9
median: 3.8
p95: 14.3
p99: 20.5
Scenario counts:
0: 2400 (100%)
Codes:
200: 4800
302: 2400