UNPKG

@loopback/docs

Version:
106 lines (75 loc) 3.25 kB
--- lang: en title: 'Application generator' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar permalink: /doc/en/lb4/Application-generator.html --- ### Synopsis Creates a new LoopBack4 application using REST API. ```sh lb4 [app] [options] [<name>] ``` ### Options `--applicationName` : Application class name. `--description` : Description of the application. `--outDir` : Project root directory for the application. `--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. `--vscode`: Add VSCode config files to LoopBack4 application project `--docker`: Generate Dockerfile and add npm scripts to build/run the project in a docker container. {% include_relative includes/CLI-std-options.md %} ### 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 <code><i>name</i>Application</code>. - 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: - [`tslint`](https://www.npmjs.com/package/tslint) - [`prettier`](https://www.npmjs.com/package/prettier) - [`mocha`](https://www.npmjs.com/package/mocha) - [`@loopback/build`](https://www.npmjs.com/package/@loopback/build) - [`vscode`](https://code.visualstudio.com/) ### Output The core scaffold of a LoopBack4 application generated by the CLI consists of the following files and directories: ```text . ├── src/ | ├── __tests__/ | ├── controllers/ | | └── ping.controller.ts | ├── datasources/ | ├── models/ | ├── repositories/ | ├── application.ts | ├── index.ts | ├── migrate.ts | └── sequence.ts └── 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 application 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](Controller-generator.md) can be run from the application's root directory to further scaffold the application.