Skip to content

bilaschandra/nest-api

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. We can run the application by the docker/docker-compose. We dockerized the application. Here we have applied the MySQL 8.

Play with NestJS 9.

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

NestJS 9 - Working with migrations using TypeORM

When configuring TypeORM, we can set the synchronize property to true. This causes TypeORM to synchronize the database with our entities automatically. However, using it in production is highly discouraged because it might lead to unexpected data loss.

Instead, TypeORM has a tool that helps us create and run migrations. Unfortunately, its migration documentation is outdated and does not match the latest version.

We also need to add some entries to the scripts in our package.json.

"typeorm:cli": "ts-node ./node_modules/typeorm/cli",
"migration:generate": "npm run typeorm:cli -- -d ./src/typeorm.config.ts migration:generate ./src/migrations/$npm_config_name",
"migration:create": "npm run typeorm:cli -- migration:create ./src/migrations/$npm_config_name",
"migration:run": "npm run typeorm:cli migration:run -- -d ./src/typeorm.config.ts"

Create a new migration script

$ npm run migration:create --name=NameOfMigration

Generate a new migration script

$ npm run migration:generate --name=NameOfMigration

Run the migration script

$ npm run migration:run

Note: If you use the docker-compose then you can do same thing inside the container. Example

$ docker-compose exec nest-api sh

You will go inside docker container. Now you can create the migration script there.

$ npm run migration:create --name=NameOfMigration

OR

run you can directly create the migration script by the command

$ docker-compose exec nest-api sh -c "npm run migration:create --name=NameOfMigration"

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

Scaffold quickly your next TypeScript API with this opinionated NestJS template crafted for Docker environments

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors