Skip to main content
Version: 2.16.2

Generate

In order to provide a better developer experience, the ExpressoTS CLI provides a set of commands to help you scaffold the application resources such as use cases, controllers, DTO's, providers and services.

This command allows developers to stay ahead of the curve by generating the boilerplate code for the application, so they can focus on the business logic.

Command syntax

One big advantage of the ExpressoTS CLI is the ability to scaffold resources using two different structures: the shorthand and the folder/subfolder/resource. The shorthand operation is a more concise way to scaffold resources (recommended to be used in the opinionated template), while the folder/subfolder/resource structure is more flexible and can be used in both templates.

The generate command can be executed as follows:

expressots generate <resource> <structure> [options]

Or in its short form:

expressots g <resource-alias> <structure> [options]
Full form
expressots generate service user/create
Short form
expressots g s user/create

Command structure

We provide two different structures to scaffold the resources, the shorthand and the folder/subfolder/resource. These scaffold strategies work differently based on the project template used. The opinionated template provides a more structured project, while the non-opinionated template provides a more flexible project structure.

Using single name

expressots g c user
Output
src
└── user.controller.ts

Using the shorthand operation

expressots g c user-create
Output
src
└── user
└── create
└── user-create.controller.ts

Using the folder/subfolder/resource structure

expressots g c user/create
Output
src
└── user
└── create.controller.ts

If you add / at the end of the structure, the CLI will create the resource inside of the folder. Example: expressots g c user/create/

Output
src
└── user
└── create
└── create.controller.ts
info

Opinionated templates come with predefined folder structures for each resource type, ensuring that resources are always created in the following designated folders:

  • useCases
  • entities
  • providers

The root folder for all resources is the src folder. This can be changed in the expressots.config.ts file.

Resource types

Resources available to be scaffolded are:

Long formshortCommandExpected result
usecaseuexpressots g u user/findUse case to be created in the folder useCases with this folder structure: user/find
controllercexpressots g c user/findController to be created in the folder useCases inside of user/find
dtodexpressots g d user/findDTO to be created in the folder useCases inside of user/find
providerpexpressots g p email/emailProvider to be created in the folder providers inside of user/find
servicesexpressots g s user/findService creates usecase, controller and DTO and add them in the desired folder user/find
entityeexpressots g e userEntity to be created in the folder entities with this folder structure: user
middlewaremiexpressots g mi authMiddleware to be created in the folder middlewares with this folder structure: auth
modulemoexpressots g mo userModule to be created in the folder where controllers and usecases are located

For services, you can take advantage of creating the use case, controller and DTO at once.

expressots g s user-create
Output for the non opinionated template
src
└── user
└── create
├── user-create.controller.ts
├── user-create.dto.ts
├── user-create.usecase.ts
└── user-create.usecase.ts
info

The expressots.config.ts file, located in the project root folder, defines where all resources will be created and specifies the naming conventions for each type of resource.

Read more about the ExpressoTS Config File.


Support us ❤️

ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please read our support guide.