Skip to content

A Simple NestJS application for my blog series, using postgres, elasticsearch and docker/docker compose

Notifications You must be signed in to change notification settings

jplindgren/Bloggering

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov``

# database (Postgres with docker)

As we want to follow using docker, here you will find how to configure the Postgres database with docker for our local development environment. Make sure that you have the docker installed and running in your machine.

First we need to run the following command to get the postgres image .

    docker pull postgres

After finishing the image download, we will run the command:

    docker run --name postgres -e POSTGRES_PASSWORD={password} -d -p 5432:5432 postgres

It will create and start the postgres docker container, using the default user **postgres** and the password **12345678a** to connect to the database.
Now we will create the database to our application.

Run the following command to open the container bash terminal.

    docker exec -it postgres /bin/bash

Now inside the container, lets run the command:

    psql -h localhost -U postgres -W

After running the previous command the database password will be asked. Type the password in the terminal.

You will receive a feedback in the terminal. Now you are connected to the postgres. Now we just need to create the database. Just run the following command:

     create database bloggering;

Now you can list all databases to check

     \list (\l)

And connect to the new database

    \connect (\c) bloggering

Database configuration comes from enviroment variables:
    TYPEORM_HOST
    TYPEORM_PORT
    TYPEORM_USERNAME
    TYPEORM_PASSWORD
    TYPEORM_DATABASE

## Initialize Containers (including Nest app)

See [Adding Docker with multi-stage build](https://blog.logrocket.com/containerized-development-nestjs-docker/)

```bash
docker-compose --project-name bloggering up --build --renew-anon-volumes --detach
(or)
docker-compose -p bloggering up --build -V -d
(after)
docker-compose up --build -V

docker-compose -p bloggering down

Once you rename the project directory to the app you want to build, you can drop the project flag for 'bloggering' in the example above. It just names the network to be consistent with the container names from docker-compose.yml.

generate jwt key

node -e require('crypto').randomBytes(256).toString('base64')

License

Nest and this project are MIT licensed.

About

A Simple NestJS application for my blog series, using postgres, elasticsearch and docker/docker compose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published