Nest framework TypeScript starter repository.
In this starter you may find a working application pre configured with the PostgreSQL and JWT Auth.
Please go through Nest Docs before playing with the code.
To run the application you need to have PostgreSQL installed.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# debug mode
$ npm run start:debug
# production mode
$ npm run start:prod
With Docker you can run it easily. Now port 3000
will be open and 9229
can be connected to debugger as well.
PostgreSQL is exposed via 5432
port.
$ docker-compose up
The project setup follows standard NestJS conventions. Checkout NestJS docs for more.
Directory structure follows module based on features.
src
โโโ @types # type defs goes here
โโโ common # common stuffs
โ โโโ decorators # custom decorators
โ โโโ dto # common DTOs
โ โโโ exceptions # exceptions
โ โโโ filters # filters for app
โ โโโ guards # guards for app
โโโ config # app config
โโโ database # database module
โ โโโ migrations # db migrations
โ โโโ stubs # migration/seed stubs
โโโ modules # modules of app
โโโ auth # auth module
โ โโโ dto
โโโ health # health module
โโโ user # user module
โโโ dto
โโโ entities
For database we have used PostgreSQL. And for ORM we have used Knex.js with ObjectionJS.
Knex is an awesome query builder which is closer to SQL. Objection also a thin wrapper around Knex.
For all database migrations please use snake_case
conversion when creating tables or columns.
In PostgreSQL it is natural to work with snake_case
when writing queries.
Knex will automatically map your snake_case
names into camelCase
on application side. Dont use snake_case
in JS side. Instead always use camelCase
. Read more
Please change the database name in docker-compose file and .env
Api docs can be geneated thanks to @nestjs/swagger
package. Since we are using cli
plugin you can comment your Dto
s with JSDocs and the documentation will be done automatically. Please follow conventions mentioned here
- Access swagger docs at http://localhost:3000/api-docs
- Access swagger.json at http://localhost:3000/api-docs-json
Env Variable | Description | example |
---|---|---|
SECRET | Secret for JWT | somesecret |
DATABASE_URL | PostgreSQL connection string | postgres://admin:admin@localhost:5432/wavezync |
LOGGER_LEVEL | Level of logger | info |
LOGGER_FORMAT | Format for logging | pretty or json |
You can find helpers by pressing CTRL + SHIFT + P
in VSCode