A simple Nest.js user API to apply some Nest.js framework concepts.
This API is not meant to be used in production. Use it only as a reference.
- Create user ✔
- Retrieve all users ✔
- Retrieve user by id ✔
- Delete user ✔
- Update user info ✔
- Login ✔
- Add .env file ✔
- Add database configuration ✔
- Add migrations WIP
- Add some simple authentication/authorization (JWT) ✔
- Unit testing ✔
- Add Docker to run the application
- Add proper typing
- Add OpenAPI documentation ✔
- Add logging ✔
- Add proper error handling ✔
- Restructure the project when everything is ready ✔
- Node.js version 14
- Nest.js
- Jest
- Docker
- PostgresSQL
- TypeORM
- Requirements:
- Node.js version 14+
- NPM
-
Run
npm install
to install all the project dependencies -
To start the application, run
npm run start
FYI: Some database configuration may be necessary, I've used my own on this project.
-
Run tests:
$ npm run test
-
Run tests with coverage:
$ npm run test:cov
-
curl --location --request POST 'http://localhost:3000/users' \ --header 'Content-Type: application/json' \ --data-raw '{ "firstName": "Sample", "lastName": "User", "address": "Sample Street", "email": "sample@email.com", "password": "userpass" }'
-
curl --location --request GET 'http://localhost:3000/users'
-
curl --location --request GET 'http://localhost:3000/users/8a072a35-4d9a-49ec-ab6f-0517e2791b13
-
curl --location --request PUT 'http://localhost:3000/users/id' \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJsYWJsYUBhLmNvbSIsImlhdCI6MTYyMjUxNzY0NSwiZXhwIjoxNjIyNTE3NzY1fQ.vBIFWQu8K73uJrpbF9-bmNK09nAR16WgAzpW0y8Bepo' \ --header 'Content-Type: application/json' \ --data-raw '{ "firstName": "Sample", "lastName": "Update", "address": "Update Street", "email": "update@email.com" }'
-
curl --location --request DELETE 'http://localhost:3000/users/8a072a35-4d9a-49ec-ab6f-0517e2791b13' \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJsYWJsYUBhLmNvbSIsImlhdCI6MTYyMjUxNzY0NSwiZXhwIjoxNjIyNTE3NzY1fQ.vBIFWQu8K73uJrpbF9-bmNK09nAR16WgAzpW0y8Bepo'
-
curl --location --request POST 'http://localhost:3000/users/login' \ --header 'Content-Type: application/json' \ --data-raw '{ "username": "blabla@a.com", "password": "123456" }'
- The documentation is available at Swagger and as a JSON file located at the user-sample-api folder