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:

  1. npm install -g @loopback/cli

Generating LoopBack projects

CommandsDescriptionSee
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

CommandsDescriptionSee
lb4 controllerAdd a new controller to a LoopBack 4 applicationController generator
lb4 datasourceAdd a new datasource to a LoopBack 4 applicationDataSource generator
lb4 modelAdd a new model to a LoopBack 4 applicationModel generator
lb4 relationAdd a relation between two models in a LoopBack 4 applicationRelation generator
lb4 repositoryAdd new repositories for selected model(s) to a LoopBack 4 applicationRepository generator
lb4 serviceAdd a new remote or local service to a LoopBack 4 applicationService generator
lb4 openapiGenerate controllers and models from OpenAPI specsOpenAPI generator
lb4 discoverDiscover models from relational databasesModel Discovery
lb4 observerGenerate life cycle observers for application start/stopLife cycle observer generator
lb4 interceptorGenerate interceptorsGlobal 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:
InputCaseClass NameModel File Names
MyModelInput remains the sameMyModelmy-model.model.ts
my_modelUnderscores get removedMyModelmy-model.model.ts
mymódelAccented characters get replacedMymodelmymodel.model.ts
Car4shareInput contains digitsCar4Sharecar-4-share.model.ts
MyModel2Input ends with digitsMyModel2my-model2.model.ts
My-ModelClass name cannot contain some symbolsInvalidInvalid
4userClass name cannot start with a numberInvalidInvalid