A feature-rich, NestJS-based REST API that simulates an e-commerce backend. It provides a complete set of features including user authentication, product and category management, and a shopping cart system. This project is built with a focus on best practices and serves as an excellent learning resource for building scalable server-side applications with TypeScript, TypeORM, and creating automated API documentation workflows.
- Authentication: Secure user registration, login, and token refresh using JWT and Argon2 for password hashing.
- Product Management: Full CRUD operations for products, including multi-image uploads, advanced filtering, and sorting capabilities.
- Category Management: Create and manage a hierarchical category structure.
- User & Cart: User profile management (including avatar uploads) and a persistent shopping cart for each user.
- API Documentation: Automatically generated, detailed API documentation using Swagger and Widdershins.
- Validation: Robust request validation using
class-validatorandclass-transformer. - Security: Hardened with
helmet, request rate-limiting, and global exception filtering for consistent error handling. - Logging: Configured with
winstonfor structured, rotating logs.
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL with TypeORM
- Authentication: JWT (JSON Web Tokens)
- API Specification: Swagger (OpenAPI)
- Logging: Winston
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
- Node.js (v18 or higher recommended)
- npm or another package manager
- A running instance of PostgreSQL
-
Clone the repository:
git clone https://github.com/nodewalker/fake-store-api.git cd fake-store-api -
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root directory by copying the example file:cp .env.dev .env
Update the
.envfile with your local configuration, especially your database credentials and a secureJWT_SECRET.# SERVER PORT=3000 # DATABASE DB_HOST='localhost' DB_PORT=5432 DB_USERNAME='your_postgres_user' DB_PASSWORD='your_postgres_password' DB_NAME='fake-store-api' # JWT JWT_SECRET='a_very_strong_and_long_secret_key'
-
Database Setup: Ensure your PostgreSQL server is running and you have created a database with the name specified in your
.envfile (e.g.,fake-store-api). The application uses TypeORM'ssynchronize: truefeature for development, which will automatically create the database schema on startup.
-
Development mode (with hot-reload):
npm run start:dev
The server will start on the port specified in your
.envfile (default:3000). -
Production mode: First, build the project:
npm run build
Then, start the compiled application:
npm run start:prod
This repository includes a comprehensive, pre-generated API reference located in the /docs directory. You can browse the files directly on GitHub to understand all available endpoints, request parameters, and response models.
To regenerate the documentation after making changes to API controllers or DTOs, run the following command:
npm run generate:gitbookThis script will:
- Generate an up-to-date
swagger.jsonfile. - Convert the OpenAPI specification into detailed Markdown files for each API resource.
- Organize the documentation structure and navigation in
docs/SUMMARY.md.
-
Unit Tests:
npm run test -
End-to-End (E2E) Tests:
npm run test:e2e
-
Test Coverage:
npm run test:cov
This project is licensed under the MIT License - see the LICENSE file for details.