This is a backend application for a Contact Management System, built with Node.js, Express, TypeScript, and Prisma. It provides a RESTful API for user authentication and managing contacts, along with an admin endpoint for API statistics.
- User Authentication: Register new users and log in with existing credentials.
- Contact Management (CRUD):
- Create new contacts.
- Retrieve a list of all contacts (with pagination and search).
- Get details of a specific contact by ID.
- Update existing contacts.
- Delete contacts.
- Admin API Statistics: An authenticated endpoint to view API usage statistics.
- JWT-based Authorization: Secure API endpoints using JSON Web Tokens.
- Logging: Structured logging using
pino. - API Documentation: Automatically generated API documentation using Swagger.
- Backend: Node.js, Express.js
- Language: TypeScript
- Database ORM: Prisma
- Database: MariaDB (or any other supported by Prisma)
- Authentication: JWT (JSON Web Tokens)
- Logging: Pino
- API Documentation: Swagger
- Testing: Jest, Supertest
- Code Quality: Prettier
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js (v20.x or higher recommended)
- DBMS
-
Clone the repository:
git clone https://github.com/otakmager/be-cms.git
-
Install dependencies:
npm install
Create a .env file in the root directory of the project based on .env.example file.
-
Generate Prisma Client:
npm run gen
-
Run database migrations:
npm run migrate
Follow the prompts to apply the migrations.
To run the application in development mode with hot-reloading:
npm run devThe API will be available at http://localhost:3000 (default).
- Build the project:
npm run build
- Start the server:
npm start
Once the server is running, you can access the API documentation (Swagger UI) at:
http://localhost:3000/docs
To run all unit tests:
npm testTo run tests and view coverage report:
npm test -- --coverage