Examples
Each example starts in a workspace where the plugin is initialised and @astrojs/check is installed.
Content collections
Section titled “Content collections”For Astro 6 and newer.
nx g @geekvetica/nx-astro:application notesimport { defineCollection } from 'astro:content';import { glob } from 'astro/loaders';import { z } from 'astro/zod';
const blog = defineCollection({ loader: glob({ pattern: '**/*.md', base: './src/content/blog' }), schema: z.object({ title: z.string(), date: z.coerce.date(), }),});
export const collections = { blog };---title: First postdate: 2026-01-15---
Hello from a content collection.---import { getCollection, render } from 'astro:content';import Layout from '../../layouts/Layout.astro';
export async function getStaticPaths() { const posts = await getCollection('blog'); return posts.map((post) => ({ params: { id: post.id }, props: { post } }));}
const { post } = Astro.props;const { Content } = await render(post);---
<Layout title={post.data.title}> <h1>{post.data.title}</h1> <Content /></Layout>check generates the types of the collection first, through sync:
nx run-many -t check build -p notesThe post is in dist/apps/notes/blog/first-post/index.html.
Server rendering with Node
Section titled “Server rendering with Node”init has already installed the @astrojs/node adapter.
nx g @geekvetica/nx-astro:application apiimport { defineConfig } from 'astro/config';import node from '@astrojs/node';
export default defineConfig({ output: 'server', adapter: node({ mode: 'standalone' }), outDir: '../../dist/apps/api',});import type { APIRoute } from 'astro';
export const GET: APIRoute = () => Response.json({ now: new Date().toISOString() });nx build apiHOST=127.0.0.1 PORT=4321 node dist/apps/api/server/entry.mjshttp://127.0.0.1:4321/api/time answers with the current time.
To run the server outside the workspace, write a package.json and a lock file next to it:
nx build api --generatePackageJson --outputPath=../../dist/apps/apiShared component library
Section titled “Shared component library”Share code between apps builds a library with an Astro component and uses it in an app. An app that is generated after the library gets its alias automatically:
nx g @geekvetica/nx-astro:application shop---import Button from '@acme/ui/Button.astro';---
<Button href="/cart">Open the cart</Button>nx build shopSeveral sites
Section titled “Several sites”Give the sites a common tag:
nx g @geekvetica/nx-astro:application marketing --tags=type:sitenx g @geekvetica/nx-astro:application handbook --tags=type:siteBuild all of them, or those a change affects:
nx run-many -t build -p tag:type:sitenx affected -t buildGive each a fixed port, so that they can run side by side:
import { defineConfig } from 'astro/config';
export default defineConfig({ output: 'static', server: { port: 4332 }, outDir: '../../dist/apps/handbook',});nx run-many -t dev -p marketing,handbook