Start a new project with Nx

When you start a new project with Nx, you have two options.

Option 1: Manual setup

In a nutshell, this means using your favorite CLI to create your initial project setup and then adding Nx to it.

Let's take the example of an NPM workspace. Create a new root-level package.json like:

1{ 2 "name": "my-workspace", 3 "version": "1.0.0", 4 "private": true, 5 "workspaces": ["packages/*", "apps/*"] 6} 7

Then you can add Nx to it by using:

nx init

(Note, make sure you have Nx installed globally or use npx if you're in a JavaScript environment)

Nx will detect the underlying workspace configuration, ask you a couple of questions and install itself into the workspace. As you keep going, you can incrementally add functionality, like:

Option 2: Guided setup (JavaScript only)

Alternatively, you can choose a more guided approach by leveraging some of the presets Nx comes with.

Run the following command to get started:

npx create-nx-workspace@latest

This interactive command will guide you through the setup process, allowing you to:

  • Choose your workspace name - This will be the name of your root directory
  • Select your preferred package manager - npm, yarn, or pnpm
  • Pick a preset - Choose from various technology stacks and configurations
  • Configure additional options - Such as styling solutions, testing frameworks, and more

Choose a preset that matches your technology stack. This gives you a fully configured workspace.

You can also choose an empty workspace preset which sets up the bare minimum configuration including Nx itself. This allows you to add technologies and features incrementally over time as you need them.