API PetShop project with Nest framework TypeScript.
-
Criandonovo projeto usando CLI:
nest new projectName
-
Criando módulos usando CLI:
nest generate module backoffice
-
Criando controller usando CLI:
nest generate controller customer
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
-
joi for validations:
npm install joi --save
npm install @hapi/joi --save-dev
-
Mongoose for MongoDB
npm i --save @nestjs/mongoose mongoose
-
NestJS/config to save enviroments variables (relys on dotenv). Documentation: https://docs.nestjs.com/techniques/configuration
npm i --save @nestjs/config
-
NestJS/swagger for API documentation
npm install @nestjs/swagger swagger-ui-express --save
-
NestJS/CQRS
npm install @nestjs/cqrs --save
-
TypeORM with Postgres
npm install --save @nestjs/typeorm typeorm pg
-
Passport to authenticate with JWT Bearer
npm install --save @nestjs/passport passport passport-http-bearer
npm install --save @nestjs/jwt passport-jwt
-
Typescript Guid:
npm i guid-typescript --save
-
MD5 to encrypt users password
npm install md5-typescript --save
-
Cache manager
npm install cache-manager --save
-
Data compression
npm install compression --save
- The application makes use of MongoDB with docker. To install the latest version of mongodb with docker (latest) use the command:
docker pull mongo
- To create a container named mongodb, run the command below replacing the values of the
MONGO_INITDB_ROOT_USERNAME
andMONGO_INITDB_ROOT_PASSWORD
fields to the desired username and password.docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=dbuser -e MONGO_INITDB_ROOT_PASSWORD=myPassword mongo
- Command to stop execution:
docker stop mongodb
- To start the same container again:
docker start mongodb
- For the application to work correctly it is necessary to use
.env
files containing the sensitive data used by the application. The file must contain the following properties:
MONGO_DB_USER=wurthmann
MONGO_DB_PASSWORD=YourPassword
MONGO_DB_HOST=localhost
MONGO_DB_PORT=27017
MONGO_DB_NAME=petshop
POSTGRES_USER=postgres
POSTGRES_PASSWORD=YourPassword
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB_NAME=petshop_store
SALT_KEY=SOME GUID SALT KEY
JWT_STRATEGY_KEY=1e3883bafe60
The suported .env
files is in app.module.ts:
envFilePath: ['.env', '.env.production', '.env.homolog', '.env.development', '.env.development.local'],