Sign inSign up

carlosempd/test-nestjs-api

By carlosempd

•Updated over 3 years ago

Image
0

228

carlosempd/test-nestjs-api repository overview

⁠NestJS API with Mongo and Mongoose

⁠Enviroment Variables

Variable de entornovalordescripción
MONGO_USERNAMEdbuserUsername for mongoDB
MONGO_PASSWORDalgun-passwordpassword for db
MONGO_DB_NAMEapiMongoDBName of db to use
JWT_SECRETAlgunValorSecretoSecret to configure hash of login tokens
SALT_ROUNDS10Numeric value to configure the encrypt for password when creating and saving a new user.

⁠Configuration to run the image in a container

To run this app using docker it would be necessary to create a folder with two files:

  • docker-compose.yaml
  • .env

In the .env file is where you will put the environment variables described up here. And in the docker-compose.yaml file is where you will configure the mongodb service that is required in order to the app works properly.

You can run this Image with the docker run command, but it is more easy doing it with the docker compose file since you need to configure the env variables and the mongodb service.

Here are examples for this files:

.env
MONGO_PASSWORD=12345
MONGO_DB_NAME=test-api-mongo
JWT_SECRET=ThisIsMyJwtSecret125463156135
SALT_ROUNDS=10
docker-compose.yaml

services:
  app:
    image: carlosempd/test-nestjs-api
    depends_on:
      - db
    ports:
      - 3000:3000
    environment:
      - MONGO_USERNAME=${MONGO_USERNAME}
      - MONGO_PASSWORD=${MONGO_PASSWORD}
      - MONGO_DB_NAME=${MONGO_DB_NAME}
      - JWT_SECRET=${JWT_SECRET}
      - SALT_ROUNDS=${SALT_ROUNDS}
  db:
    image: mongo:5
    container_name: ${MONGO_DB_NAME}
    restart: always
    ports:
      - 27017:27017
    environment:
      - MONGODB_DATABASE=test-mongo-api
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
    volumes:
      - mongo-test:/data/db
    command: ['--auth']

volumes:
 mongo-test:
  external: false

Finally, open a terminal inside the folder created with the two files metioned above and run: docker compose up

This will download this image with the latest version (unless you specify one) and the mongo image and will mount the container with the app running.

After that, open in the browser http://localhost:3000/api⁠ and you should be able to see the endpoints via swagger documentation.

Tag summary

Content type

Image

Digest

sha256:4337e9245…

Size

62.3 MB

Last updated

over 3 years ago

docker pull carlosempd/test-nestjs-api