https://github.com/agodin3z/nest-typeorm-template
TypeORM + NestJS API Template
https://github.com/agodin3z/nest-typeorm-template
nestjs typeorm typeorm-seeding
Last synced: 25 days ago
JSON representation
TypeORM + NestJS API Template
- Host: GitHub
- URL: https://github.com/agodin3z/nest-typeorm-template
- Owner: agodin3z
- License: mit
- Created: 2023-06-04T18:29:04.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T14:58:48.000Z (over 1 year ago)
- Last Synced: 2024-10-19T21:37:56.004Z (over 1 year ago)
- Topics: nestjs, typeorm, typeorm-seeding
- Language: TypeScript
- Homepage:
- Size: 2.62 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TypeORM + NestJS API Template
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
## Tech Stack
- [NestJS](https://nestjs.com/) - A progressive Node.js framework for building efficient, reliable and scalable server-side applications.
- [TypeORM](https://typeorm.io/) - An ORM that can run many platforms and can be used with TypeScript and JavaScript.
- [Jest](https://jestjs.io/) - Delightful JavaScript Testing Framework with a focus on simplicity.
- [Husky](https://typicode.github.io/husky/) - Git hooks made easy dog woof!
- [ESLint](https://eslint.org/) - Find and fix problems in your JavaScript code.
- [Prettier](https://prettier.io/) - An opinionated code formatter.
- [Lint Staged](https://github.com/okonet/lint-staged) - Run linters on git staged files.
- [CommitLint](https://commitlint.js.org/) - Lint commit messages.
## Prerequisites
- [Volta](https://volta.sh/)* (node, npm, and yarn version manager)
> \* Optional dependency, alternatives: [n](https://github.com/tj/n) or [nvm](https://github.com/nvm-sh/nvm)
### Optional Development Prerequisites
Install the following dependencies:
- [Docker Desktop](https://docs.docker.com/desktop/) (An one-click-install application that enables you to build and share containerized applications and microservices.)
- [Docker Compose](https://docs.docker.com/compose/install/) (Plugin for running multi-container Docker applications)
Then create a `docker.env` file with the following values:
```env
MYSQL_DATABASE=awesome_db
MYSQL_USER=user
MYSQL_PASSWORD=passwd
MYSQL_ROOT_PASSWORD=secret_passwd
```
Finally, run docker containers from `docker-compose.yml` file with `docker-compose up -d` command or run it with Docker Desktop.
## Getting Started
### Enviroment config
Create a copy of `.env.example` with the name `.env` and `.env.test.example` with the name `.env.test` and placed it at the root of the project
```bash
cp .env.example .env
cp .env.test.example .env.test
```
Replace its values with your own credentials.
### Install Dependencies
Run the following commands to install all dependencies:
```bash
volta install node
volta install yarn
yarn
```
## Development server
Run `yarn start:dev` to start a development server that watch for changes. For a debug server use: `yarn start:debug`
## Running unit tests
Run `yarn test` to execute the unit tests via [Jest](https://jestjs.io/). For coverage test use: `yarn test:cov`
## Build for production
Run `yarn build` to compile for production, this will execute `prebuild` and `postbuild` commands automatically. Then run `yarn start:prod` to start a production server.
## Scripts API Reference
### Server
| Script | Description |
| :----------------- | :---------------------------------------- |
| `yarn start` | Start server (without watch) |
| `yarn start:dev` | Start development server |
| `yarn start:debug` | Start debug development server |
| `yarn start:prod` | Start production server |
| `yarn pm2` | Run production server as Cluster with PM2 |
| `yarn pm2:restart` | Reload API with PM2 |
| `yarn pm2:stop` | Stop PM2 service |
| `yarn pm2:logs` | View PM2 logs |
### Build
| Script | Description |
| :--------------- | :----------------------- |
| `yarn prebuild` | Clean dist folder |
| `yarn build` | Build project |
### Lint & Format
| Script | Description |
| :------------ | :------------------------- |
| `yarn format` | Format files with Prettier |
| `yarn lint` | Lint files with ESLint |
### Tests
| Script | Description |
| :---------------- | :----------------------- |
| `yarn test` | Run test (without watch) |
| `yarn test:watch` | Run test and watch |
| `yarn test:cov` | Run coverage test |
| `yarn test:e2e` | Run end-to-end tests |
| `yarn test:debug` | Debug tests |
### TypeORM
| Script | Description |
| :---------------------------- | :----------------------------------------------------------------------------- |
| `yarn typeorm` | Access to TypeORM CLI commands. |
| `yarn migrations` | Applies all pending migrations, and creates the database if it does not exist. |
| `yarn migrations:create` | Creates a new migration file. |
| `yarn migrations:test` | Run migrations for test |
| `yarn migrations:revert` | Revert migrations in DB |
| `yarn migrations:revert:test` | Revert migrations in test DB |
| `yarn migrations:generate` | Generate a migration from existing table schema and entities |
| `yarn seeds` | Polulate DB with seed data |
> For more information on TypeORM, read the [official documentation](https://typeorm.io/using-cli)
### Misc
| Script | Description |
| :--------------------- | :--------------------------------------------------------------------- |
| `docker-compose up -d` | Builds, (re)creates, starts, and attaches to containers for a service. |