Documentation 🤟

This page will guide you through the different steps to start with TeanJS

To be able to start the project right a way, the only thing you will have to do is update the server environments of your database in the file ./server/environments/local/database.ts.

Then, your next action will be to run the following command npm run migration:run. This will result in the creation of your first users table base on the migration file located in the migrations directory ./server/migrations.

Features

Often, when you start a new project, you will have a look on the existing start. But the major problem is that there is too many features that you don't need or not enough. So you have to deal with something you don't really want.

That's why, the amount of features in that starter stay limited (to avoid forcing you to use something you don't want) but enough to be ready to code.

Server

For start, let see the modules available

The Users module provide you some basic features such as

  • Create a new user

  • Find a user by Id

To achieve that, you have in your possession a users.service.ts file that encapsulate the logic to manage the users.

You will find also a user.entity.ts that describe your users and along it, a custom user.repository.ts (will see that later) and a user.subscriber-entity.ts that separate the entity behavior logic from the entity itself. The subscriber as one purpose which is to hash/Salt the user password during the creation process.

Beside these modules, the common directory comes with some useful features

EntityNotFoundExceptionHandler

These decorator only wrap a method that use TypeORM to make some action. If that action result in an error of type EntityNotFound it will catch it and redirect that error as an EntityNotFoundException which will be handle by a custom filter. It's an example that show how to handle error and unified them to get a common error output.

LoggedInUser

When a user has been logged in your api, you will have it ready on your Request object. This decorator is made to be able to grab it into your controller method as an argument.

It's the perfect example of usage of customDecorator in NestJS.

Server

All the environments for the server are stored in the ./server/environments. In that directory there is the root files used in the application (e. g. to setup the database connection) and the local directory where you will be able to set the default values of all the environment configurations. That way, you can have a generic configuration file that will use the env variables if possible or the default values provided by the files situated in the local directory.

In the .gitignore file, there is the following statement: # /server/environments/local/

Please remove the # to avoid pushing your password and other sensitive environment configurations anywhere. You must never push your ./server/environments/local directory at any point.

Here is a non exhaustive list of the main commands available:

Last updated