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.

Node Server Tutorial - Part 1: Code Generation

In this tutorial you'll create a backend-focused workspace with Nx.


Your Objective

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:



npx create-nx-workspace@latest

✔ Choose what to create · node-standalone ✔ Application name · products-api ✔ What framework should be used? · express ✔ Would you like to generate a Dockerfile? [] · Yes Enable distributed caching to make your CI faster · Yes
Opting into Nx Cloud

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.

The node-standalone preset automatically creates a products-api application at the root of the workspace and an e2e project that runs against it.

Framework Options

This tutorial uses the express framework. The node-standalone preset also provides starter files for koa and fastify. For other frameworks, you can choose none and add a it yourself.

Generating Libraries

To create the auth library, use the @nx/node:lib generator:

Nx Generator Syntax



npx nx g @nx/node:lib auth --buildable

> NX Generating @nx/node:library CREATE auth/ 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 UPDATE jest.config.ts UPDATE project.json CREATE auth/jest.config.ts CREATE auth/tsconfig.spec.json
Nx 15 and lower use @nrwl/ instead of @nx/

You have now created three projects:

  • products-api in /
  • e2e in /e2e
  • auth in /auth

What's Next