Important:Before running this generator, you must create an application using the application generator.Then you must run the command from the root directory of the application.

Synopsis

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

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

Options

—type : (Optional) service type: proxy, class, or provider

—datasource : (Optional) name of a valid REST or SOAP datasource alreadycreated in src/datasources

Configuration file

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

  1. {
  2. "name": "serviceNameToBeGenerated",
  3. "datasource": "validDataSourceName",
  4. }

Remote and local services

We support three types of services now:

  • proxy: A service proxy for remote REST/SOAP/gRPC APIs
  • class: A TypeScript class that can be bound to the application context
  • provider: A TypeScript class that implements Provider interface and can bebound to the application contextFor remote services (type=proxy), there should be at least one valid (REST orSOAP) 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: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 argument specifying the service name to be generated.

Interactive prompts

The tool will prompt you for:

  • Service type.(serviceType) If the service type had been supplied fromthe command line with —type or —datasource (implying proxy) option andit is a valid one, then the prompt is skipped, otherwise it will present youthe list of all valid service types.
  1. ? Service type: (Use arrow keys)
  2. Remote service proxy backed by a data source
  3. Local service class bound to application context
  4. Local service provider bound to application context
  • Please select the datasource.(datasource) If the name of the datasourcehad been supplied from the command line with —datasource option and it is avalid one, then the prompt is skipped, otherwise it will present you the listof all valid datasources from the src/datasources directory.

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

Output

Once all the prompts have been answered, the CLI will generate a basicskeleton 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.