This is a microservice for user management, built with NestJS. The service provides endpoints for user registration, login, password reset and more.
These are some of tech that the project uses:
- NestJS - A progressive Node.js framework.
- Typescript - TypeScript is JavaScript with syntax for types.
- Typeorm - TypeORM is an ORM that can run in NodeJS.
- Postgres - Relational Database.
- JWT - JSON Web Tokens.
- Docker - Docker and Docker Compose
The following environment variables are required for this microservice. They are declared on .env file.
DB_HOST
- The hostname of the database.DB_PORT
- The port of the database.DB_USERNAME
- The username for the database.DB_PASSWORD
- The password for the database.DB_NAME
- The name of the database.APP_PORT
- The port for the microservice.JWT_SECRET
- The secret used to sign JWT tokens.JWT_EXPIRES
- The amount of time a JWT token should be valid for.EMAIL_HOST
- The hostname of the email server.EMAIL_PORT
- The port of the email server.SMTP_SECURE
- Whether to use secure SMTP.EMAIL_USER
- The username for the email account.EMAIL_PASSWORD
- The password for the email account.EMAIL_FROM
- The from address for email notifications.EMAIL_CONFIRMATION_URL
- The URL to confirm a user's email address.THROTTLE_TTL
- The time-to-live for rate limiting in seconds.THROTTLE_LIMIT
- The number of requests allowed per time-to-live.
Install the dependencies, run migrations and start the server.
npm install
npm run migration:run
npm run start
You can also start the app using Docker. The docker-compose file provides three containers: api-service : API app. postgres : PostgreSQL database with initial data (users table and one user row) pgadmin : Web-based management tool for PostgreSQL
docker-compose up -d
Create a new user account.
Path: /users/register
Method: POST
Request Body:
{ "email": "[email protected]", "password": "secretpassword", "firstName": "John", "lastName": "Doe" }
Retrieve a list of all users. This endpoint is only accessible by administrators.
Path: /users
Retrieve the details of a single user, by ID. This endpoint is only accessible by administrators.
Path: /users/:id
Method: GET
Example Request: /users/1
Send a password reset email to the specified email address.
Path: /users/reset-password
Method: POST
Request Body:
{ "email": "[email protected]" }
Change a user's password.
Path: /users/change-password Method: PUT
Request Body:
{ "userId": "user-id-123", "oldPassword": "old-password", "newPassword": "new-password" }
Delete a user account.
Path: /users/:id
Method: DELETE
Authenticate a user and retrieve a JSON Web Token.
Path: /auth/login
Method: POST
Request Body:
{ "email": "[email protected]", "password": "secretpassword" }
Confirm a user's email address.
Path: /auth/confirm-email
Method: POST
Request Body:
{ "token": "token generated" }
Develop in nodejs version 16.19.0.