This project contains a NodeJS API using the followed technologies:
- 🔥
node- as web server - 💨
express- the web framework - 🎲
mongoose- a odm to interact withmongodb - 🔑
jwt- for authentication - ⚗️
jest- for automated testing - 💪
supertest- for integration testing - ✔️
eslint- for static code analysis
To execute this project on your machine you'll need to follow the steps bellow.
nodeandnpmmust be previously installed- you'll also need of the
mongodbinstalled and running
In order to execute this project, you'll need a copy of his files. Clone this repository to get all project files.
Copy the .env.example file, paste at the root project folder and rename it to .env and fill the all the asked fields.
npm run lint:check- to check all project filesnpm run lint:staged- to check only staged filesnpm run lint:write- to fix all errors detected by lint tool
Open a terminal at the root project folder and run:
npm run test:unit- for unit testsnpm run test:integration- for integration testsnpm run test- for all tests
Open a terminal at the root project folder and run: npm run dev
You can use a toll like postman or insomnia to test the resources of this api. Make sure the server is running. Listed bellow are some resources avaliables.
- POST
/signin- Return a token for use in private routes - POST
/signout- Return a token withnullvalue
- GET
/users- List all users - POST
/users- Create a new user - GET
users/:id- Retrive a user - PUT
users/:id- Update a user - DELETE
users/:id- Remove a user
- GET
/properties- List all properties - POST
/properties- Create a new property - GET
properties/:id- Retrive a property - PUT
properties/:id- Update a property - DELETE
properties/:id- Remove a property
Except for /signin and /signout, all routes needs an authentication token. To get this is necessary make a request in /signin route passing in the body of the request a previusly registred email and password, and the response will be return a token. Use it in x-access-token header in next requests.
Make a POST request at https://zupi.herokuapp.com/signin passing in the body of the request the following JSON:
{
"email": "[email protected]",
"password": "barney"
}The response will be something like this
{
"token": "eyJhbGciOiJIUzI1NiIsnR5cCI6IkpXVCJ9.eyJpZCI6IjViYTQwMD5N2I3YzU3MDAxNWRlMDYxNCIsImlhdCI6MTUzNzQ3NzkyNiwiZXhwIjoxNTM3NTY0Mz2fQ.7vTYl0R6zftTNVqjTJXgYRh2y4CDNndMCrTVpo6agU"
}Explore others routes as described in the step How to execute.