Skip to main content

Overview

The CLI (command-line interface) tool helps you to create ExpressoTS projects and scaffold ExpressoTS resources.

We use the npm in this tutorial for simplicity. However, you can use your preferred package manager (yarn or pnpm) by replacing npm with the appropriate command.

Installation

First install the CLI globally using the command below:

npm install -g @expressots/cli

Commands available

The CLI provides the following commands:

NameAliasDescription
new projectnewGenerate a new project
infoiProvides project information
resourcesrDisplays CLI commands and resources
scriptsscriptsRun scripts list or a specific script
helphelpShow command help
serviceg sGenerate a service [controller, usecase, dto, module]
controllerg cGenerate a controller
usecaseg uGenerate a usecase
dtog dGenerate a DTO
entityg eGenerate an entity
providerg pGenerate internal provider
provideraddAdd external provider to the project
providercreateCreate external provider
moduleg moGenerate a module
middlewareg miGenerate a middleware

Usage examples

The CLI has the following syntax:

expressots <command> [options]

Help command

Verify the available commands and options:

expressots help

Info command

Providers information about your Operational System, Project and CLI version:

expressots info

Resources list

List all available resources to scaffold:

expressots resources (Alias: r)

Create a project

There are two options to create a new project, interactively or silently (passing the options as arguments). Here is the complete command syntax:

Create project command options
expressots new <project-name> -p <package-manager> -t <template> -d <directory>

Interactively

expressots new <project-name>

Silently

expressots new <project-name> -p <package-manager> -t <template> -d <directory>
  • package-manager: npm, yarn or pnpm
  • template: opinionated or non-opinionated
  • directory: ./my-project

The flag -d is optional and is used to specify the directory where the project will be created. If not specified, the project will be created in the current directory.

Add a provider

Add an external provider to the project:

expressots add <provider-name>

Although you can add npm registry packages, the primary use case for this command is to add providers that were built specifically for ExpressoTS.

Watch for updates of our Providers App Store.

Create a provider

Create a new ExpressoTS provider. For more information about providers, check the Providers section.

expressots create <provider-name>

Scaffold resources

The CLI provides commands to scaffold resources like controller, usecase, dto, entity, module and middleware.

expressots generate <resource> <name> [options]

Resources are created in the src directory by default. They also can be scaffolded in 2 different ways: passing the path or using the shorthand operation.

caution

The resource scaffolding operations produce different results 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.

Passing the path

Create a controller named user inside the services directory
expressots g c services/user
Output
src
└── services
└── user.controller.ts

Shorthand operation

Create a controller named services-user inside the services/user directory
expressots g c services-user
Output
src
└── services
└── user
└── services-user.controller.ts

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.