LoopBack 4 provides command-line tools to help you get started quickly. Thecommand line tools generate application and extension projects and install theirdependencies for you. The CLI can also help you generate artifacts, such ascontrollers, for your projects. Once generated, the scaffold can be expandedwith users’ own code as needed.
To use LoopBack 4’s CLI, run this command:
npm install -g @loopback/cli
Generating LoopBack projects
Commands | Description | See |
---|---|---|
lb4 | Create a new LoopBack4 application | Application generator |
lb4 extension | Create a new LoopBack4 extension | Extension generator |
lb4 example | Download one of LoopBack example projects | Download examples |
Generating LoopBack artifacts
Commands | Description | See |
---|---|---|
lb4 controller | Add a new controller to a LoopBack 4 application | Controller generator |
lb4 datasource | Add a new datasource to a LoopBack 4 application | DataSource generator |
lb4 model | Add a new model to a LoopBack 4 application | Model generator |
lb4 relation | Add a relation between two models in a LoopBack 4 application | Relation generator |
lb4 repository | Add new repositories for selected model(s) to a LoopBack 4 application | Repository generator |
lb4 service | Add a new remote or local service to a LoopBack 4 application | Service generator |
lb4 openapi | Generate controllers and models from OpenAPI specs | OpenAPI generator |
lb4 discover | Discover models from relational databases | Model Discovery |
lb4 observer | Generate life cycle observers for application start/stop | Life cycle observer generator |
lb4 interceptor | Generate interceptors | Global interceptor generator |
Naming Convention
LoopBack 4 uses different convention for naming classes, variables, and files.
- Class name:
PascalCase
. - File name:
kebab-case
. - Variable name:
camelCase
.Here are some examples:
Input | Case | Class Name | Model File Names |
---|---|---|---|
MyModel | Input remains the same | MyModel | my-model.model.ts |
my_model | Underscores get removed | MyModel | my-model.model.ts |
mymódel | Accented characters get replaced | Mymodel | mymodel.model.ts |
Car4share | Input contains digits | Car4Share | car-4-share.model.ts |
MyModel2 | Input ends with digits | MyModel2 | my-model2.model.ts |
My-Model | Class name cannot contain some symbols | Invalid | Invalid |
4user | Class name cannot start with a number | Invalid | Invalid |