{"library":"nitro-nightly","title":"Nitro Universal Server Framework","description":"Nitro is a versatile framework for building and deploying universal JavaScript servers, extending existing Vite applications with production-ready server capabilities. The `nitro-nightly` package represents the active development line for Nitro v3, which is currently in beta. Nitro v3 aims for a significantly smaller install size (down to 9MB), near-native runtime performance, and enhanced features like experimental tracing channels and smarter dependency tracing. While the stable release series remains v2, `nitro-nightly` provides access to cutting-edge features and improvements for upcoming major versions. Nitro focuses on a \"run anywhere\" philosophy, abstracting deployment complexities, and often offers a zero-configuration experience for common use cases. New `nitro-nightly` releases are frequent, reflecting active development and testing against real-world projects.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install nitro-nightly"],"cli":{"name":"nitro","version":null}},"imports":["import { defineEventHandler } from 'nitro';","import { eventHandler } from 'nitro';","import { useRuntimeConfig } from 'nitro';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { defineEventHandler, createApp, toNodeListener, useRuntimeConfig } from 'nitro';\nimport { listen } from 'listhen';\n\n// Define a simple server route\nconst helloHandler = defineEventHandler(() => {\n  const message = 'Hello from Nitro!';\n  const date = new Date().toISOString();\n  // Example of using runtime config (though not explicitly set here)\n  const secretKey = process.env.MY_SECRET_KEY ?? 'default_secret';\n  console.log(`Request received at ${date}. Using secret: ${secretKey}`);\n  return { api: message, timestamp: date, secretUsed: secretKey };\n});\n\nconst userHandler = defineEventHandler((event) => {\n  const name = event.context.params?.name || 'Guest';\n  return { message: `Hello, ${name}!` };\n});\n\n// Create a Nitro application\nconst app = createApp();\n\n// Add routes to the app\napp.router.get('/', helloHandler);\napp.router.get('/api/hello/:name', userHandler);\napp.router.get('/api/config', defineEventHandler(() => {\n  const config = useRuntimeConfig(); // Access runtime config\n  return {\n    public: config.public,\n    serverSecret: config.serverSecret // Example of a server-only secret\n  };\n}));\n\n// Define configuration for the server\nconst serverConfig = {\n  host: process.env.HOST || '0.0.0.0',\n  port: parseInt(process.env.PORT || '3000')\n};\n\n// Start the server\nasync function startServer() {\n  const listener = toNodeListener(app);\n  console.log(`Nitro server running on http://${serverConfig.host}:${serverConfig.port}`);\n  await listen(listener, serverConfig);\n}\n\nstartServer().catch((error) => {\n  console.error('Failed to start Nitro server:', error);\n  process.exit(1);\n});","lang":"typescript","description":"This quickstart demonstrates how to create a basic Nitro server, define multiple API routes using defineEventHandler, access request parameters, and start the server. It also shows a placeholder for accessing runtime configuration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}