Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

nitropack

БесплатноБез исполняемых скриптовНе проверен

Builds portable server applications with Nitro (nitropack), the server engine behind Nuxt, Analog and SolidStart: file-based routes, middleware, a storage…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Nitro — Universal Server Engine

Overview

Nitro turns a folder of handlers into a server that builds to a self-contained .output/ directory. The same code runs on Node.js, Bun, Deno, Cloudflare Workers, Vercel, Netlify, AWS and others; the build target is chosen by a preset. Nuxt uses Nitro for everything under its server/ directory, so this skill applies to Nuxt server routes too.

Two lines exist side by side (checked October 2026):

  • Nitro 2 — npm package nitropack (2.13.x, latest). H3 version 1 underneath. Auto-imports of defineEventHandler, useStorage and friends. This is what this skill's examples use, and what Nuxt 3/4 ship.
  • Nitro 3 — npm package nitro (3.0 beta). H3 version 2, no auto-imports, directory scanning is opt-in, useStorage is renamed useKV. See "Moving to Nitro 3" below before starting a new project on it.

Instructions

Create a project

npx giget@latest nitro orders-api --install    # starter template (Nitro 2, nitropack)
cd orders-api
npm run dev          # nitro dev, http://localhost:3000
npm run build        # writes .output/
npm run preview      # node .output/server/index.mjs (PORT or NITRO_PORT sets the port)

The starter's nitro.config.ts sets srcDir: "server" and imports: false. Two consequences that surprise people:

  • With a bare nitropack install and no srcDir, Nitro scans routes/, api/, middleware/, tasks/ at the project root, not under server/. A server/routes/users.post.ts then returns 404 with no warning. Set srcDir: "server" (Nuxt already does).
  • With imports: false there are no auto-imports: import { defineEventHandler, getRouterParam } from "h3" and import { useStorage } from "nitropack/runtime". The examples below omit imports, which works only when auto-imports are on (the default when you write your own config, and always in Nuxt).

Routes

Files under server/routes/ map to URLs; server/api/ adds the /api prefix. A .get.ts/.post.ts suffix pins the method, [id] is a param, [...slug] a catch-all, and .dev.ts/.prod.ts limits a file to one build mode. One handler per file.

// server/routes/users/[id].get.ts  ->  GET /users/42
export default defineEventHandler(async (event) => {
  const id = getRouterParam(event, "id");
  const user = await useStorage("db").getItem(`users:${id}`);
  if (!user) throw createError({ statusCode: 404, message: "User not found" });
  return user;
});

// server/routes/users.post.ts  ->  POST /users
export default defineEventHandler(async (event) => {
  const body = await readBody(event);
  if (!body?.name || !body?.email) {
    throw createError({ statusCode: 400, message: "name and email are required" });
  }
  const id = crypto.randomUUID();
  await useStorage("db").setItem(`users:${id}`, { id, ...body, createdAt: Date.now() });
  setResponseStatus(event, 201);
  return { id, ...body };
});

Middleware and utils

Files in server/middleware/ run before every route. A middleware may change the request or event.context; it must not return a value, because a returned value becomes the response and stops the request. Files in server/utils/ are auto-imported (Nitro 2 with imports on).

// server/middleware/auth.ts
export default defineEventHandler(async (event) => {
  if (getRequestURL(event).pathname.startsWith("/api/public")) return;
  const token = getHeader(event, "authorization")?.replace("Bearer ", "");
  if (!token) throw createError({ statusCode: 401, message: "Unauthorized" });
  event.context.user = await verifyToken(token);   // verifyToken lives in server/utils/
});

Storage (unstorage)

useStorage(base) is a key-value layer over drivers. The first argument is a mount point; keys use : separators. Without configuration the default mount is in memory and is lost on restart.

// nitro.config.ts
export default defineNitroConfig({
  srcDir: "server",
  compatibilityDate: "2025-01-30",
  storage: {
    db: { driver: "fs", base: "./.data/db" },                      // local files
    sessions: { driver: "redis", url: process.env.REDIS_URL },     // see unstorage drivers
  },
  devStorage: { sessions: { driver: "fs", base: "./.data/sessions" } },  // dev only
});

Mount points root, src, build and cache exist in development; do not reuse the name cache for your own data, because Nitro's response cache lives there. For credentials that are not known at build time, mount the driver in a defineNitroPlugin using useRuntimeConfig().

Caching

// server/routes/stats.get.ts — cached 1 hour, stale value served while refreshing
export default defineCachedEventHandler(() => computeStats(), { maxAge: 60 * 60 });

// server/utils/github.ts — cache any function; results must be JSON-serializable
export const cachedStars = defineCachedFunction(
  async (repo: string) => (await $fetch<any>(`https://api.github.com/repos/${repo}`)).stargazers_count,
Полный SKILL.md на GitHub

Установить nitropack в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл nitropack?

Builds portable server applications with Nitro (nitropack), the server engine behind Nuxt, Analog and SolidStart: file-based routes, middleware, a storage layer, response caching, scheduled tasks and one build that targets Node.js, Bun, Deno, Cloudflare, Vercel, Netlify and AWS. Use when a user asks to create a Nitro server, add API routes or tasks, configure storage, pick a deployment preset, or move from Nitro 2 to Nitro 3.

Как установить скилл nitropack?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл nitropack запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить nitropack с