Skip to content

Latest commit

 

History

History
183 lines (132 loc) · 6.58 KB

README.md

File metadata and controls

183 lines (132 loc) · 6.58 KB

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 Discord Backers on Open Collective Sponsors on Open Collective

Description

NestJS Framework server project generated from official JHipster NodeJS blueprint.

Installation

$ npm install

TypeORM configuration

Define your prod database

As default your project will use an sqlite database (or a mongodb in memory). For prod database configuration, you don't have to do nothing if you use a docker-compose with a project database image. To use other custom instance, in src/orm.config.ts change database, host, port, username and password according your values:

if(process.env.BACKEND_ENV==='prod'){
  ormconfig = {
      ...
      database: 'YOUR_DATABASE_NAME'
      host: 'localhost',
      port: 3307,
      username: 'sa',
      password: 'yourStrong(!)Password',
      logging: false,
      synchronize: commonConf.SYNCRONIZE,
      entities: commonConf.ENTITIES,
      migrations: commonConf.MIGRATIONS,
      cli: commonConf.CLI,
      migrationsRun: commonConf.MIGRATIONS_RUN,
  };
}

To use it at runtime read the below section.

Migration data and schema

According typeORM migration guide, there are under src/migrations/ the scripts to create the database schema and after to insert data seed. The scripts are automatically run in the first start up, and after anymore.

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# build transpiling files in javascript
$ npm run build

# run javascript build from the source project
$ npm run start:prod

# run javascript build with node
$ node dist/main.js

# build bundle with webpack
$ npm run webpack:prod

# run bundle with node (not require node_modules folder)
$ node dist/bundle.js

Using .env file and run in prod

The app uses a BACKEND_ENV variable with dev default value in the .env file. If you change the value to prod, you will use the prod database at runtime as defined in src/orm.config.ts. You can also define all the variables that you want in that file. See https://www.npmjs.com/package/dotenv for the usage.

The standard values used from BACKEND_ENV are: dev, prod or test. You can define your custom value for BACKEND_ENV, but remember to add an application-{BACKEND_ENV}.yml file in your config folder, and a database configuration for that environment value, according the src/orm.config.ts.

If you don't want to set a value in the .env file, you can specify its in the runtime process. For example:

# development in prod environment
# in linux
$ BACKEND_ENV=prod npm run start
# in windows
$ set BACKEND_ENV=prod&& npm run start

# run javascript build with node in prod environment
# in linux
$ BACKEND_ENV=prod node dist/main.js
# in windows
$ set BACKEND_ENV=prod&& node dist/main.js

# run bundle with node (not require node_modules folder)
$ node dist/bundle.js

The webpack build bundle automatically is configured for prod env, and can run without node_modules.

Lint

# run lint
$ npm run lint

# fix lint issues
$ npm run lint:fix

Debug

# run this and after you can execute debug task in VSCode
$ npm run start:debug

Test

# unit tests
$ npm run test

# lint
$ npm run lint

# fix lint issues
$ npm run lint:fix

# test coverage of unit tests
$ npm run test:cov

# e2e tests with full app coverage report
$ npm run test:e2e

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.