Giter Club home page Giter Club logo

nestjs-with-typeorm's Introduction

Description

This repository provides a basic scaffold for a NestJS project with TypeORM and database migration.

Installation

$ npm install

Running the app

With CLI

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Debugging with predefined launch.json

Swagger at http://localhost:3000/swagger

Docker ๐Ÿณ

Coming soon.

Database migration

We use PostgreSQL in this project. Please ensure that the database instance is up and running.

1. Config database connection

Please put .env file in root folder like this:-

# .env
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASENAME=postgres

migration script will use DataSource specified in src/data-source.ts

# src/data-source.ts
dotenv.config({ path: path.join(__dirname, '..', './.env') });

export default new DataSource({
    type: 'postgres',
    host: process.env.DB_HOST,
    port: +process.env.DB_PORT,
    username: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASENAME,
    synchronize: false,
    logging: true,
    entities: [__dirname + '/**/*.entity{.ts,.js}'],
    migrations: [__dirname + '/migrations/*{.ts,.js}'],
    migrationsTableName: '__migrations_history',
    schema: 'public'
});

2. CLI

migration scripts are specified in pacakge.json

# For Windows ๐ŸชŸ

# to generate migration
$ npm run migration-windows:generate --name=migration_name  # This will generate migration file in src/migrations

# to run migration (apply)
$ npm run migration:run # This will run migrations in src/migrations


# For Linux ๐Ÿง

# to generate migration
$ npm run migration-linux:generate --name=migration_name # This will generate migration file in src/migrations

# to run migration (apply)
$ npm run migration:run # This will run migrations in src/migrations

License

Nest is MIT licensed.

nestjs-with-typeorm's People

Contributors

manooi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.