This is an API for a contacts book that allows managing contacts.
- Express.js - Web application framework for Node.js
- Mongoose - Object Data Modeling (ODM) library for MongoDB and Node.js
- bcrypt - Library for hashing passwords
- cors - Middleware for handling Cross-Origin Resource Sharing (CORS)
- Gravatar - Library for getting user avatars from Gravatar
- Joi - Data validation library
- jsonwebtoken - Library for creating and verifying JSON Web Tokens (JWT)
- morgan - HTTP request logger middleware
- multer - Middleware for handling file uploads in
multipart/form-data
format
- Clone the repository:
git clone https://github.com/taranvd/nodejs-homework-rest-api.git
- Navigate to the project folder:
cd nodejs-homework-rest-api
- Install dependencies:
npm install
- Start server in production mode:
npm start
- Start server in development mode:
npm run start:dev
- Run ESLint for code check (execute before each PR and fix all lint errors):
npm run lint
- Run ESLint with automatic fixes for simple errors:
npm run lint:fix
-
POST
/register
: User registration. Validates the request body against the specified schema and callsAuthController.register
. -
POST
/login
: User login. Validates the request body against the specified schema and callsAuthController.login
. -
GET
/current
: Get current user's information. Protected by theauthenticate
middleware. -
POST
/logout
: User logout. Protected by theauthenticate
middleware. -
PATCH
/avatars
: Update user's avatar. Protected by theauthenticate
middleware and expects a file upload usingmulter
. -
GET
/verify/:token
: Verify user account by providing the verification token. -
POST
/verify
: Request email verification. Validates the request body against the specified schema.
-
GET
/
: Get the list of contacts. Protected by theauthenticate
middleware. -
GET
/:contactId
: Get a specific contact by ID. Protected by theauthenticate
middleware, validates the contact ID, and checks if the authenticated user is the owner. -
POST
/
: Add a new contact. Protected by theauthenticate
middleware, validates the request body. -
PATCH
/:contactId/favorite
: Update the favorite status of a contact. Protected by theauthenticate
middleware, validates the contact ID, and checks if the authenticated user is the owner. -
DELETE
/:contactId
: Remove a contact by ID. Validates the contact ID. -
PUT
/:contactId
: Update a contact by ID. Protected by theauthenticate
middleware, validates the contact ID, and checks if the authenticated user is the owner.