Page Contents

Synopsis

Adds a new Service class to a LoopBack application with one single command.

lb4 service [options] [<name>]

Options

--datasource : (Optional) name of a valid REST or SOAP datasource already created in src/datasources

Configuration file

This generator supports a config file with the following format, see the Standard options below to see different ways you can supply this configuration file.

{
  "name": "serviceNameToBeGenerated",
  "datasource": "validDataSourceName",
}

Notes

There should be at least one valid (REST or SOAP) data source created already in the src/datasources directory.

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:fix

For example,

lb4 app --config config.json
lb4 app --config {"name":"my-app"}
cat config.json | lb4 app --config stdin
lb4 app --config stdin < config.json
lb4 app --config stdin << EOF
> {"name":"my-app"}
> EOF
-y, --yes
Skip all confirmation prompts with default or provided value

Arguments

<name> - Optional argument specifyng the service name to be generated.

Interactive Prompts

The tool will prompt you for:

  • Please select the datasource. (datasource) If the name of the datasource had been supplied from the command line with --datasource option and it is a valid one, then the prompt is skipped, otherwise it will present you the list of all valid datasources from the src/datasources directory.

  • Service name. (name) If the name of the service to be generated had been supplied from the command line, the prompt is skipped.

Output

Once all the prompts have been answered, the CLI will generate a basic skeleton for your service.

  • Create a Service class as follows: /src/services/${name}.service.ts
  • Update /src/services/index.ts to export the newly created Service class.