Page Contents

Synopsis

Creates a new LoopBack4 application using REST API.

lb4 [app] [options] [<name>]

Options

--tslint
Add TSLint to LoopBack4 application project.
--prettier
Add Prettier to LoopBack4 application project.
--mocha
Add Mocha to LoopBack4 application project.
--loopbackBuild
Add @loopback/build module’s script set to LoopBack4 application project.

Standard options

-h, --help
Print the generator’s options and usage.
--skip-cache
Do not remember prompt answers. Default is false.
--skip-install
Do not automatically install dependencies. Default is false.

Arguments

<name> - Optional name of the application given as an argument to the command.  If provided, the tool will use that as the default when prompting for the name.

Interactive Prompts

The tool will prompt you for:

  • Name of the application as will be shown in package.json. If the name had been supplied from the command-line, the prompt is skipped and the application is built with the name from the command-line argument. Must follow npm naming conventions.

  • Description of the application as will be shown in package.json.

  • Name of the directory in which to create your application. Defaults to the name of the application previously entered.

  • Name of the Application class in application.ts. Defaults to nameApplication.

  • Optional modules to add to the application. These modules are helpful tools to help format, test, and build a LoopBack4 application. Defaults to true for all of the modules. The prompted modules are:

Output

The core scaffold of a LoopBack4 application generated by the CLI consists of the following files and directories:

.
├── src/
|   ├── controllers/
|   |   └── ping.controller.ts
|   ├── datasources/
|   ├── models/
|   ├── repositories/
|   ├── application.ts
|   ├── index.ts
|   └── sequence.ts
├── test/
└── package.json

ping.controller.ts is a file used to provide the application with a responsive endpoint. It contains logic to respond with a greeting message when the appliaction receives a GET request from endpoint /ping.

cd to the application’s newly created directory and run npm start to see the application running at localhost:3000. Go to localhost:3000/ping to be greeted with a message.

Once the application has been created, additional generators such as controller generator can be run from the application’s root directory to further scaffold the application.