Quick Start
Try Nitro online
Get a taste of Nitro in your browser using our playground.
Create a Nitro project
The fastest way to create a Nitro application is with create-nitro-app.
npx create-nitro-app
yarn dlx create-nitro-app
pnpm dlx create-nitro-app
bunx create-nitro-app
deno run -A npm:create-nitro-app
Preview
Follow the CLI instructions and you will be ready to start your development server.
Add to a Vite project
You can add Nitro to any existing Vite project to get API routes, server-side rendering, and more.
Install nitro and vite
npm i nitro vite
yarn add nitro vite
pnpm i nitro vite
bun i nitro vite
deno i npm:nitro vite
Add Nitro plugin to Vite
Add the Nitro plugin to your vite.config.ts:
import { defineConfig } from "vite";
import { nitro } from "nitro/vite";
export default defineConfig({
plugins: [
nitro()
],
});
Configure Nitro
Create a nitro.config.ts to configure the server directory:
import { defineConfig } from "nitro";
export default defineConfig({
serverDir: "./server",
});
The serverDir option tells Nitro where to look for your server routes. In this example, all routes will be inside the server/ directory. By default serverDir is false, so no directories are scanned until you set it (or scanDirs).
Create an API route
Create your first API route at server/api/test.ts:
import { defineHandler } from "nitro";
export default defineHandler(() => {
return { message: "Hello Nitro!" };
});
The file path maps directly to the route URL — server/api/test.ts becomes /api/test. Handlers can return strings, JSON objects, Response instances, or readable streams.
routes config option. See Programmatic route handlers for more details.Start the development server
npm run dev
yarn dev
pnpm dev
bun run dev
deno run dev
Your API route is now accessible at http://localhost:3000/api/test ✨
Next steps
- Learn about dynamic routes, methods, and middleware in Routing.
- Serve HTML or a single-page app for unmatched routes with the renderer.
- Take full control of every request with a server entry.