* 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
100 lines
3.8 KiB
Markdown
100 lines
3.8 KiB
Markdown
---
|
|
title: 'Node Tutorial - Part 1: Code Generation'
|
|
description: In this tutorial you'll create a backend-focused workspace with Nx.
|
|
---
|
|
|
|
{% callout type="check" title="Two Styles of Repo" %}
|
|
There are two styles of repos: integrated and package-based. This tutorial shows the integrated style.
|
|
|
|
You can find more information on the difference between the two in [our introduction](/getting-started/intro).
|
|
{% /callout %}
|
|
|
|
# Node Tutorial - Part 1: Code Generation
|
|
|
|
In this tutorial you'll create a backend-focused workspace with Nx.
|
|
|
|
## Contents
|
|
|
|
- [1 - Code Generation](/node-tutorial/1-code-generation)
|
|
- [2 - Project Graph](/node-tutorial/2-project-graph)
|
|
- [3 - Task Running](/node-tutorial/3-task-running)
|
|
- [4 - Workspace Optimization](/node-tutorial/4-workspace-optimization)
|
|
- [5 - Summary](/node-tutorial/5-summary)
|
|
|
|
## Your Objective
|
|
|
|
For this tutorial, you'll create an Express API application, a CLI (command-line interface) application, and a library for a data client that these two applications will use to interact with a data-source.
|
|
|
|

|
|
|
|
## Creating an Nx Workspace
|
|
|
|
Run the command `npx create-nx-workspace@latest` and when prompted, provide the following responses:
|
|
|
|
```{% command="npx create-nx-workspace@latest" path="~" %}
|
|
✔ Choose your style · integrated
|
|
✔ What to create in the new workspace · express
|
|
✔ Repository name · my-products
|
|
✔ Application name · products-api
|
|
✔ Enable distributed caching to make your CI faster · No
|
|
```
|
|
|
|
{% card title="Opting into Nx Cloud" description="You will also be prompted whether to add Nx Cloud to your workspace. We won't address this in this tutorial, but you can see the introduction to Nx Cloud for more details." url="/nx-cloud/intro/what-is-nx-cloud" /%}
|
|
|
|
Once the command complete, you can find your Express API application in `apps/products-api`.
|
|
|
|
## Adding Another Application to Your Workspace
|
|
|
|
Run this command to create your `products-cli` app:
|
|
|
|
```{% command="npx nx g @nrwl/node:app products-cli" path="~/my-products" %}
|
|
|
|
> NX Generating @nrwl/node:application
|
|
|
|
CREATE apps/products-cli/src/app/.gitkeep
|
|
CREATE apps/products-cli/src/assets/.gitkeep
|
|
CREATE apps/products-cli/src/environments/environment.prod.ts
|
|
CREATE apps/products-cli/src/environments/environment.ts
|
|
CREATE apps/products-cli/src/main.ts
|
|
CREATE apps/products-cli/tsconfig.app.json
|
|
CREATE apps/products-cli/tsconfig.json
|
|
CREATE apps/products-cli/project.json
|
|
CREATE apps/products-cli/.eslintrc.json
|
|
CREATE apps/products-cli/jest.config.ts
|
|
CREATE apps/products-cli/tsconfig.spec.json
|
|
```
|
|
|
|

|
|
|
|
## Generating Libraries
|
|
|
|
To create the `products-data-client` library, use the `@nrwl/js:lib` generator:
|
|
|
|
```{% command="npx nx g @nrwl/js:lib products-data-client" path="~/my-products" %}
|
|
|
|
> NX Generating @nrwl/js:library
|
|
|
|
CREATE libs/products-data-client/README.md
|
|
CREATE libs/products-data-client/package.json
|
|
CREATE libs/products-data-client/src/index.ts
|
|
CREATE libs/products-data-client/src/lib/products-data-client.spec.ts
|
|
CREATE libs/products-data-client/src/lib/products-data-client.ts
|
|
CREATE libs/products-data-client/tsconfig.json
|
|
CREATE libs/products-data-client/tsconfig.lib.json
|
|
CREATE libs/products-data-client/project.json
|
|
UPDATE tsconfig.base.json
|
|
CREATE libs/products-data-client/.eslintrc.json
|
|
CREATE libs/products-data-client/jest.config.ts
|
|
CREATE libs/products-data-client/tsconfig.spec.json
|
|
```
|
|
|
|
You have now created all three projects from the design:
|
|
|
|
- `products-api` in `apps/products-api`
|
|
- `products-cli` in `apps/products-cli`
|
|
- `products-data-client` in `libs/products-data-client`
|
|
|
|
## What's Next
|
|
|
|
- Continue to [2: Project Graph](/node-tutorial/2-project-graph)
|