nx/docs/shared/recipes/add-stack/add-fastify.md
Jack Hsu 66eaf2fc74
docs(misc): remove /nx-api pages (#31453)
This PR removes the `/nx-api` pages from `nx-dev`. They are already
redirected from `/nx-api` to either `/technologies` or
`/reference/core-api` URLs.

e.g. `/nx-api/nx` goes to `/reference/core-api/nx` and `/nx-api/react`
goes to `/technologies/react/api`

**Changes**:
- Remove old `nx-api.json` from being generated in
`scripts/documentation/generators/generate-manifests.ts` -- this was
used to generate the sitemap
- Remove `pages/nx-api` from Next.js app since we don't need them
- Remove workaround from link checker
`scripts/documentation/internal-link-checker.ts` -- the angular
rspack/rsbuild and other workarounds are gone now that they are proper
docs in `map.json`
- Update Powerpack/Remote Cache reference docs to exclude API documents
(since they are duplicated in the Intro page) --
`nx-dev/models-document/src/lib/mappings.ts`
- All content in `docs` have been updated with new URL structure

**Note:** Redirects are already handled, and Claude Code was used to
verify the updated `docs/` URLs (see report below). The twelve 404s
links were updated by hand.

## Verification Report

https://gist.github.com/jaysoo/c7863fe7e091cb77929d1976165c357a
2025-06-04 16:57:01 -04:00

3.1 KiB

title description
Add a New Fastify Project Learn how to create and configure Fastify applications and libraries in your Nx workspace using the @nx/node plugin.

Add a New Fastify Project

{% youtube src="https://www.youtube.com/embed/LHLW0b4fr2w" title="Easy, Modular Node Applications!" width="100%" /%}

Supported Features

Because we are using an Nx plugin for Fastify, all the features of Nx are available.

{% pill url="/features/run-tasks" %} Run Tasks{% /pill %} {% pill url="/features/cache-task-results" %} Cache Task Results{% /pill %} {% pill url="/ci/features/remote-cache" %} Share Your Cache{% /pill %} {% pill url="/features/explore-graph" %} Explore the Graph{% /pill %} {% pill url="/ci/features/distribute-task-execution" %} Distribute Task Execution{% /pill %} {% pill url="/getting-started/editor-setup" %} Integrate with Editors{% /pill %} {% pill url="/features/automate-updating-dependencies" %} Automate Updating Nx{% /pill %} {% pill url="/features/enforce-module-boundaries" %} Enforce Module Boundaries{% /pill %} {% pill url="/features/generate-code" %} Use Code Generators{% /pill %} {% pill url="/features/automate-updating-dependencies" %} Automate Updating Framework Dependencies{% /pill %}

Create a New Workspace with a Fastify App

If you're starting from scratch, you can use a preset to get you started quickly.

npx create-nx-workspace@latest --preset=node-monorepo --framework=fastify --appName=fastify-api

Then you can skip to the Create a Library section.

If you are adding Fastify to an existing repo, continue to the next section.

Install the Node Plugin

nx add @nx/node

Create an Application

Use the app generator to create a new Fastify app.

nx g @nx/node:app apps/fastify-api

Serve the API by running

nx serve fastify-api

This starts the application on localhost:3000/api by default.

Create a Library

To create a new library, run:

nx g @nx/node:lib libs/my-lib

Once the library is created, update the following files.

export function someFunction(): string {
  return 'some function';
}
import { someFunction } from '@my-org/my-lib';
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';

export default async function (fastify: FastifyInstance) {
  fastify.get(
    '/',
    async function (request: FastifyRequest, reply: FastifyReply) {
      return { message: 'Hello API ' + someFunction };
    }
  );
}

Now when you serve your API, you'll see the content from the library being displayed.

More Documentation