nx/docs/shared/nest-plugin.md
Zachary DeRose 1298a0f6db
docs(core): node and react tutorial rework (#12498)
* docs(react): update react tutorial text

* docs(react): fixes to computation cache lesson

* docs(react): reworking react tutorial

* docs(react): fixing broken links in tutorial

* docs(react): fixing broken more links in tutorial

* docs(react): fixing last broken link in tutorial

* docs(react): really fixing last broken link in tutorial

* fixing images in preview

* docs(react): cleaning up text and formatting issues

* docs(react): more fixes and cleanup

* docs(react): more fixes

* docs(react): fixing nx console broken links

* docs(react): adjusting ending summary cards

* docs(react): more typo fixes

* docs(react): incorporating victor and isaac's feedback

* docs(react): fixing broken link

* docs(react): a self-round of typo and formatting fixes

* docs(react): another round of formatting fixes

* docs(react): another small change

* docs(react): another typo fix

* docs(react): more typo fixed noticed working with node tutorial

* docs(react): making h1's consistent

* docs(react): fixing tab title for part 1

* docs(react): fixing the title

* docs(react): escaping colon in title

* docs(node): copying react tutorials as starting point

* docs(node): fixing map.json and links to other lessons

* docs(node): updating the copy-pasted react tutorial for the node example

* docs(node): more fixes after self-review

* docs(node): fixing another typo

* docs(node): Making h1's consistent

* docs(node): fixing tab title in step 1

* docs(node): fixing the title

* docs(node): escaping colon in title

* docs(core): nx graph => project graph

* docs(core): fixing titles

* docs(core): further shortening the text

* docs(core): formatting fixes

* docs(core): responding to victor comments

* docs(core): switching to new terminal code blocks

* docs(core): light and dark mode friendly images
2022-10-14 10:12:05 -07:00

149 lines
3.8 KiB
Markdown

Nest.js is a framework designed for building scalable server-side applications. In many ways, Nest is familiar to Angular developers:
- It has excellent TypeScript support.
- Its dependency injection system is similar to the one in Angular.
- It emphasises testability.
- Its configuration APIs are similar to Angular as well.
Many conventions and best practices used in Angular applications can be also be used in Nest.
## Setting Up Nest
To create a new workspace with Nest, run the following command:
```shell
npx create-nx-workspace my-workspace --preset=nest
```
Yarn users can use the following command instead:
```shell
yarn create nx-workspace my-workspace --preset=nest
```
To add the Nest plugin to an existing workspace, run one the following commands:
```shell
npm install -D @nrwl/nest
```
```shell
yarn add -D @nrwl/nest
```
### Create Applications
You can add a new Nest application with the following command:
```shell
nx g @nrwl/nest:app my-nest-app
```
#### Application Proxies
Generating Nest applications has an option to configure other projects in the workspace to proxy API requests. This can be done by passing the `--frontendProject` with the project name you wish to enable proxy support for.
```shell
nx g @nrwl/nest:app my-nest-app --frontendProject my-angular-app
```
### Create Libraries
You can add a new Nest library with the following command:
```shell
nx g @nrwl/nest:lib my-nest-lib
```
To make the library `buildable`, use the following command:
```shell
nx g @nrwl/nest:lib my-nest-lib --buildable
```
To make the library `publishable`, use the following command:
```shell
nx g @nrwl/nest:lib my-nest-lib --publishable --importPath=@my-workspace/my-nest-lib
```
> Read more about [building and publishing libraries here](/more-concepts/buildable-and-publishable-libraries).
### Nest Generators
The Nest plugin for Nx extends the generators provided by Nest. Any commands that can be used with the Nest CLI can also be used with the `nx` command. The `--project` flag should be used for all Nest generators.
> `--project` is used to infer the root of the project where the generators will generate the files.
## Using Nest
### Build
You can build an application with the following command:
```shell
nx build my-nest-app
```
This applies to `buildable` libraries as well
```shell
nx build my-nest-lib
```
#### Waiting for other builds
Setting the `waitUntilTargets` option with an array of projects (with the following format: `"project:architect"`) will execute those commands before serving the Nest application.
### Serve
You can serve an application with the following command:
```shell
nx serve my-nest-app
```
The `serve` command runs the `build` target, and executes the application.
By default, the serve command will run in `watch` mode. This allows code to be changed, and the Nest application to be rebuilt automatically.
#### Debugging
Nest applications also have the `inspect` flag set, so you can attach your debugger to the running instance.
Debugging is set to use a random port that is available on the system. The port can be changed by setting the port option in the `serve` target in the `project.json`. Or by running the serve command with `--port <number>`.
For additional information on how to debug Node applications, see the [Node.js debugging getting started guide](https://nodejs.org/en/docs/guides/debugging-getting-started/#inspector-clients).
### Lint
You can lint an application with the following command:
```shell
nx lint my-nest-app
```
You can lint a library with the following command:
```shell
nx lint my-nest-lib
```
### Unit Test
You can run unit test for an application with the following command:
```shell
nx test my-nest-app
```
You can run unit test for a library with the following command:
```shell
nx test my-nest-lib
```
## More Documentation
- [Using Jest](/packages/jest)