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.
Node Server Tutorial - Part 1: Code Generation
In this tutorial you'll create a backend-focused workspace with Nx.
For this tutorial, you'll create an Express API application, a library that the API can reference to handle authentication and a suite of e2e tests.
Creating an Nx Workspace
Run the command
npx create-nx-workspace@latest and when prompted, provide the following responses:
> NX Let's create a new workspace [https://nx.dev/getting-started/intro] ✔ Where would you like to create your workspace? · products-api ✔ Which stack do you want to use? · node ✔ What framework should be used? · express ✔ Standalone project or integrated monorepo? · standalone ✔ Would you like to generate a Dockerfile? [https://docs.docker.com/] · Yes ✔ Enable distributed caching to make your CI faster · Yes
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.
node-standalone preset automatically creates a
products-api application at the root of the workspace and an
e2e project that runs against it.
This tutorial uses the
express framework. The
node-standalone preset also provides starter files for
fastify. For other frameworks, you can choose
none and add a it yourself.
To create the
auth library, use the
npx nx g @nx/node:lib auth --buildable
> NX Generating @nx/node:library CREATE auth/README.md CREATE auth/.babelrc CREATE auth/package.json CREATE auth/src/index.ts CREATE auth/src/lib/auth.spec.ts CREATE auth/src/lib/auth.ts CREATE auth/tsconfig.json CREATE auth/tsconfig.lib.json UPDATE tsconfig.json UPDATE package.json CREATE auth/project.json CREATE .eslintrc.base.json UPDATE .eslintrc.json UPDATE e2e/.eslintrc.json CREATE auth/.eslintrc.json CREATE jest.config.app.ts UPDATE jest.config.ts UPDATE project.json CREATE auth/jest.config.ts CREATE auth/tsconfig.spec.json
You have now created three projects:
- Continue to 2: Project Graph