Skip to content

Jumpstart your next Typescript-based API project with this boilerplate. Our aim is to accelerate your API development while imparting essential best practices for crafting exceptional and scalable REST APIs

License

Notifications You must be signed in to change notification settings

Treblle/nestjs-api-boilerplate

Repository files navigation

Treblle's NestJS API boilerplate

Description

A boilerplate for your next Typescript based API. It's goal is to simply kick-start your API development and provide you with some of the best practices when building amazing and scalable REST APIs. 🔥

Using:

Installation

yarn

Setup

Make sure you have Postgres database running, as well as your Treblle credentials. Here are the required environment variables for running this application. Add them to your .env file.

# Postgres details
DATABASE_HOST=
DATABASE_PORT=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_NAME=

# Seed initial user details for login
INITIAL_USER_NAME=
INITIAL_USER_EMAIL=
INITIAL_USER_PASSWORD=

# String secret for generating JWTs
JWT_SECRET=

# Treblle account information: treblle.com
TREBLLE_API_KEY=
TREBLLE_PROJECT_ID=

Before running the app

Migrate with this shortcut to add required entities to your Postgres database. Check TypeORM docs here for more features.

yarn typeorm:run-migrations

Running the app

# Development
yarn start

# Watch mode
yarn start:dev

# Production mode
yarn start:prod

Other features

NestJS features

This is build upon a NestJS init project following practices from the official documentation, so check their awesome docs to learn more! All default NestJS features should work as expected, as well as the CLI.

TypeORM migrations

To generate a new migration after adding your entity, you can just run the following:

yarn typeorm:generate-migration ./src/database/migrations/Create<EntityName>

There are also shortcuts for other TypeORM CLI commands, like:

# Runs all migrations
yarn typeorm:run-migrations

# Creates a new migration file
yarn typeorm:create-migration ./src/database/migrations/<MigrationName>

# Reverts the last migration
yarn typeorm:revert-migration

Directory src/database/migrations is used for migrations by default. Don't forget to add your migrations into DatabaseModule after creating them, or else they won't be run!

License

Copyright 2022, Treblle Limited. MIT licensed.

About

Jumpstart your next Typescript-based API project with this boilerplate. Our aim is to accelerate your API development while imparting essential best practices for crafting exceptional and scalable REST APIs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published