Synopsis

Creates a new LoopBack4 application using REST API.

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

Options

—applicationName : Application class name.

—description : Description of the application.

—outDir : Project root directory for the application.

—eslint : Add ESLint 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 LoopBack4application project.

—vscode: Add VSCode config files to LoopBack4 application project

—docker: Generate Dockerfile and add npm scripts to build/run the project ina docker container.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.
  • -c, —config
  • JSON file name or value to configure options
  • —format
  • Format generated code using npm run lint:fixFor example,
  1. lb4 app --config config.json
  2. lb4 app --config '{"name":"my-app"}'
  3. cat config.json | lb4 app --config stdin
  4. lb4 app --config stdin < config.json
  5. lb4 app --config stdin << EOF
  6. > {"name":"my-app"}
  7. > EOF
  • -y, —yes
  • Skip all confirmation prompts with default or provided value

Arguments

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

Interactive Prompts

The tool will prompt you for:

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

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

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

  • Name of the Application class in application.ts. Defaults tonameApplication.

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

Output

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

  1. .
  2. ├── src/
  3. | ├── __tests__/
  4. | ├── controllers/
  5. | | └── ping.controller.ts
  6. | ├── datasources/
  7. | ├── models/
  8. | ├── repositories/
  9. | ├── application.ts
  10. | ├── index.ts
  11. | ├── migrate.ts
  12. | └── sequence.ts
  13. └── package.json

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

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

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