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:
1 2 > NX Let's create a new workspace [https://nx.dev/getting-started/intro] 3 4✔ Where would you like to create your workspace? · products-api 5✔ Which stack do you want to use? · node 6✔ What framework should be used? · express 7✔ Standalone project or integrated monorepo? · standalone 8✔ Would you like to generate a Dockerfile? [https://docs.docker.com/] · Yes 9✔ Enable distributed caching to make your CI faster · Yes 10
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
1> NX Generating @nx/node:library 2 3CREATE auth/README.md 4CREATE auth/.babelrc 5CREATE auth/package.json 6CREATE auth/src/index.ts 7CREATE auth/src/lib/auth.spec.ts 8CREATE auth/src/lib/auth.ts 9CREATE auth/tsconfig.json 10CREATE auth/tsconfig.lib.json 11UPDATE tsconfig.json 12UPDATE package.json 13CREATE auth/project.json 14CREATE .eslintrc.base.json 15UPDATE .eslintrc.json 16UPDATE e2e/.eslintrc.json 17CREATE auth/.eslintrc.json 18CREATE jest.config.app.ts 19UPDATE jest.config.ts 20UPDATE project.json 21CREATE auth/jest.config.ts 22CREATE auth/tsconfig.spec.json 23
You have now created three projects:
- Continue to 2: Project Graph