Minimal store products
June 2022: Personal project to learn JavaScript as Backend with Nestjs and TypeScript.
As Backend with PHP - Laravel I knew about APIs. So I developed the project by following some online courses, where I achieved:
- Implemented Validations, Services, environment variables, documentation with Swagger and more
- Configured NoSQL with MongoDB for the Database and Mongoose as a ODM
- Implemented Authentication with Passport.js - JWT
- Implemented Authorization with Guards
- Added some e2e Testing for basic features
Then I made a Project definition to define the main business logic with a scope that allows scalability. Defining only the necessary resources to fit the Project goal.
- Improve testing e2e: Add fixtures to make some data, test for seller and administrator role
- Add unit testing: There are some files made by default for some components, these does not work
- Add Continuous Integration: Add some GitHub Actions for the testing
- Add Docker container for the Nodejs project: The project is run in a local environment, it should in a container as database in a the same network
- Improve business logic: There are some rules to define and fix, a review after making testing
These instructions will get you a copy of the project up and running on your local machine.
The programs you need are:
- Nodejs v16.14.2
- NPM v8.5.0
- Docker.
- Docker compose.
First duplicate the file .env.example as .env.
cp .env.example .env
Then install the JavaScript dependencies:
npm install
Create the images and run the services (MongoDB and MongoExpress):
docker compose up
Create a database called nestjs-store
in Mongo Express from 8081 (http://localhost:8081/).
Finally, defines an API_KEY
in .env file and run the server
# development
$ npm run start
# watch mode
$ npm run start:dev
NODE_ENV=stag npm run start:dev
# production mode
$ npm run start:prod
NODE_ENV=prod npm run start:dev
There are a special container for testing, the following commands are used to manage it
$ npm run db:test:up
$ npm run db:test:rm
$ npm run db:test:restart
Note: there are a .env.test
file with the credentials for that testing database
Finally run the e2e testing with
$ npm run test:e2e
- Nestjs: A progressive Node.js framework
- Swagger: API Documentation & Design Tools for Teams
- Passport.js with Nestjs: Authentication middleware for Node.js
- Mongoose with Nestjs: Elegant mongodb object modeling for node.js
- PactumJS: Free & OpenSource REST API Testing Tool for all levels in a Test Pyramid
- Martín S. Campos - mascam97
You're free to contribute to this project by submitting issues and/or pull requests.
- NestJs Course for Beginners - Create a REST API > e2e tests with pactumJs
- NestJS Course: Authentication with Passport and JWT
- NestJS Course: Data Persistence with MongoDB
- NestJS Course: Modular Programming, Documentation with Swagger and Deploy
- Backend with Nestjs Course
- Postman Course
- API REST Course
- Backend Architecture Practical Course