nitro 3.0.1-alpha.2 → 3.0.260415-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +1646 -0
  4. package/dist/_build/common.mjs +7261 -3812
  5. package/dist/_build/rolldown.mjs +32 -42
  6. package/dist/_build/rollup.mjs +28 -48
  7. package/dist/_build/vite.build.mjs +10 -10
  8. package/dist/_chunks/nitro.mjs +102 -327
  9. package/dist/_chunks/nitro2.mjs +8 -9
  10. package/dist/_chunks/nitro3.mjs +136 -0
  11. package/dist/_chunks/nitro4.mjs +127 -0
  12. package/dist/_chunks/utils.mjs +40 -29
  13. package/dist/_common.mjs +13 -25
  14. package/dist/_dev.d.mts +0 -3
  15. package/dist/{_chunks/dev.mjs → _dev.mjs} +132 -330
  16. package/dist/_libs/_.mjs +2 -0
  17. package/dist/_libs/_2.mjs +2 -0
  18. package/dist/_libs/_3.mjs +2 -0
  19. package/dist/_libs/_4.mjs +2 -0
  20. package/dist/_libs/_5.mjs +2 -0
  21. package/dist/_libs/_6.mjs +2 -0
  22. package/dist/_libs/_7.mjs +2 -0
  23. package/dist/_libs/c12+rc9.mjs +814 -0
  24. package/dist/_libs/{c12+giget+readdirp+chokidar.d.mts → c12+readdirp+chokidar.d.mts} +49 -40
  25. package/dist/_libs/citty.mjs +142 -41
  26. package/dist/_libs/commondir+is-reference.mjs +60 -56
  27. package/dist/_libs/compatx.d.mts +0 -2
  28. package/dist/_libs/compatx.mjs +1 -4
  29. package/dist/_libs/esbuild.d.mts +0 -1
  30. package/dist/_libs/escape-string-regexp.mjs +1 -4
  31. package/dist/_libs/{pluginutils+plugin-commonjs.d.mts → estree+pluginutils.d.mts} +0 -5
  32. package/dist/_libs/estree-walker.mjs +4 -92
  33. package/dist/_libs/exsolve.d.mts +1 -0
  34. package/dist/_libs/hasown+resolve+deepmerge.mjs +160 -246
  35. package/dist/_libs/httpxy.d.mts +20 -13
  36. package/dist/_libs/httpxy.mjs +519 -95
  37. package/dist/_libs/js-tokens.d.mts +1 -0
  38. package/dist/_libs/klona.mjs +1 -4
  39. package/dist/_libs/magic-string.d.mts +0 -2
  40. package/dist/_libs/mlly.d.mts +0 -2
  41. package/dist/_libs/nypm+tinyexec.mjs +822 -0
  42. package/dist/_libs/perfect-debounce.mjs +68 -0
  43. package/dist/_libs/pkg-types.d.mts +0 -3
  44. package/dist/_libs/plugin-alias.mjs +1 -5
  45. package/dist/_libs/plugin-inject.mjs +1 -7
  46. package/dist/_libs/plugin-json.mjs +1 -5
  47. package/dist/_libs/pluginutils.mjs +3 -35
  48. package/dist/_libs/readdirp+chokidar.mjs +187 -365
  49. package/dist/_libs/remapping.mjs +1 -5
  50. package/dist/_libs/resolve-uri+gen-mapping.mjs +15 -53
  51. package/dist/_libs/rou3.d.mts +1 -4
  52. package/dist/_libs/rou3.mjs +223 -78
  53. package/dist/_libs/std-env.d.mts +8 -2
  54. package/dist/_libs/strip-literal.d.mts +1 -0
  55. package/dist/_libs/tsconfck.mjs +21 -334
  56. package/dist/_libs/ultrahtml.mjs +3 -16
  57. package/dist/_libs/unimport+unplugin.mjs +244 -388
  58. package/dist/_libs/unplugin+unimport.d.mts +5 -15
  59. package/dist/_libs/unwasm.d.mts +0 -3
  60. package/dist/_presets.mjs +576 -488
  61. package/dist/builder.d.mts +5 -25
  62. package/dist/builder.mjs +3 -8
  63. package/dist/cli/_chunks/build.mjs +22 -25
  64. package/dist/cli/_chunks/common.mjs +1 -4
  65. package/dist/cli/_chunks/deploy.mjs +37 -0
  66. package/dist/cli/_chunks/dev.mjs +6 -11
  67. package/dist/cli/_chunks/docs.mjs +28 -0
  68. package/dist/cli/_chunks/list.mjs +4 -8
  69. package/dist/cli/_chunks/prepare.mjs +2 -6
  70. package/dist/cli/_chunks/preview.mjs +48 -0
  71. package/dist/cli/_chunks/run.mjs +7 -11
  72. package/dist/cli/_chunks/task.mjs +1 -5
  73. package/dist/cli/index.mjs +5 -6
  74. package/dist/docs/0.docs/0.index/index.md +56 -0
  75. package/dist/docs/0.docs/1.quick-start.md +110 -0
  76. package/dist/docs/0.docs/10.lifecycle.md +204 -0
  77. package/dist/docs/0.docs/11.openapi.md +291 -0
  78. package/dist/docs/0.docs/12.plugins.md +164 -0
  79. package/dist/docs/0.docs/13.tasks.md +277 -0
  80. package/dist/docs/0.docs/14.websocket.md +386 -0
  81. package/dist/docs/0.docs/15.migration.md +213 -0
  82. package/dist/docs/0.docs/16.nightly.md +31 -0
  83. package/dist/docs/0.docs/2.renderer.md +322 -0
  84. package/dist/docs/0.docs/3.routing.md +711 -0
  85. package/dist/docs/0.docs/4.server-entry.md +239 -0
  86. package/dist/docs/0.docs/5.cache.md +408 -0
  87. package/dist/docs/0.docs/6.storage.md +261 -0
  88. package/dist/docs/0.docs/7.assets.md +166 -0
  89. package/dist/docs/0.docs/8.configuration.md +256 -0
  90. package/dist/docs/0.docs/9.database.md +185 -0
  91. package/dist/docs/1.deploy/0.index/index.md +64 -0
  92. package/dist/docs/1.deploy/1.runtimes/0.node.md +63 -0
  93. package/dist/docs/1.deploy/1.runtimes/1.bun.md +15 -0
  94. package/dist/docs/1.deploy/1.runtimes/2.deno.md +19 -0
  95. package/dist/docs/1.deploy/2.providers/0.alwaysdata.md +50 -0
  96. package/dist/docs/1.deploy/2.providers/1.aws.md +47 -0
  97. package/dist/docs/1.deploy/2.providers/10.flightcontrol.md +67 -0
  98. package/dist/docs/1.deploy/2.providers/11.genezio.md +67 -0
  99. package/dist/docs/1.deploy/2.providers/12.github-pages.md +68 -0
  100. package/dist/docs/1.deploy/2.providers/13.gitlab-pages.md +37 -0
  101. package/dist/docs/1.deploy/2.providers/14.heroku.md +84 -0
  102. package/dist/docs/1.deploy/2.providers/15.iis.md +38 -0
  103. package/dist/docs/1.deploy/2.providers/16.koyeb.md +109 -0
  104. package/dist/docs/1.deploy/2.providers/17.netlify.md +47 -0
  105. package/dist/docs/1.deploy/2.providers/18.platform-sh.md +37 -0
  106. package/dist/docs/1.deploy/2.providers/19.render.md +37 -0
  107. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +81 -0
  108. package/dist/docs/1.deploy/2.providers/20.stormkit.md +24 -0
  109. package/dist/docs/1.deploy/2.providers/21.vercel.md +270 -0
  110. package/dist/docs/1.deploy/2.providers/22.zeabur.md +19 -0
  111. package/dist/docs/1.deploy/2.providers/23.zephyr.md +99 -0
  112. package/dist/docs/1.deploy/2.providers/24.zerops.md +102 -0
  113. package/dist/docs/1.deploy/2.providers/3.azure.md +72 -0
  114. package/dist/docs/1.deploy/2.providers/4.cleavr.md +33 -0
  115. package/dist/docs/1.deploy/2.providers/5.cloudflare.md +369 -0
  116. package/dist/docs/1.deploy/2.providers/6.deno-deploy.md +66 -0
  117. package/dist/docs/1.deploy/2.providers/7.digitalocean.md +46 -0
  118. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  119. package/dist/docs/1.deploy/2.providers/9.firebase.md +32 -0
  120. package/dist/docs/2.config/0.index/index.md +1221 -0
  121. package/dist/docs/3.examples/0.index/index.md +3 -0
  122. package/dist/docs/3.examples/1.api-routes.md +145 -0
  123. package/dist/docs/3.examples/10.hono.md +74 -0
  124. package/dist/docs/3.examples/11.import-alias.md +97 -0
  125. package/dist/docs/3.examples/12.middleware.md +91 -0
  126. package/dist/docs/3.examples/13.mono-jsx.md +68 -0
  127. package/dist/docs/3.examples/14.nano-jsx.md +70 -0
  128. package/dist/docs/3.examples/15.plugins.md +91 -0
  129. package/dist/docs/3.examples/16.renderer.md +113 -0
  130. package/dist/docs/3.examples/17.runtime-config.md +97 -0
  131. package/dist/docs/3.examples/18.server-fetch.md +87 -0
  132. package/dist/docs/3.examples/19.shiki.md +198 -0
  133. package/dist/docs/3.examples/2.auto-imports.md +92 -0
  134. package/dist/docs/3.examples/20.virtual-routes.md +74 -0
  135. package/dist/docs/3.examples/21.vite-nitro-plugin.md +79 -0
  136. package/dist/docs/3.examples/22.vite-rsc.md +1041 -0
  137. package/dist/docs/3.examples/23.vite-ssr-html.md +217 -0
  138. package/dist/docs/3.examples/24.vite-ssr-preact.md +247 -0
  139. package/dist/docs/3.examples/25.vite-ssr-react.md +226 -0
  140. package/dist/docs/3.examples/26.vite-ssr-solid.md +256 -0
  141. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +442 -0
  142. package/dist/docs/3.examples/28.vite-ssr-tss-react.md +444 -0
  143. package/dist/docs/3.examples/29.vite-ssr-vue-router.md +617 -0
  144. package/dist/docs/3.examples/3.cached-handler.md +81 -0
  145. package/dist/docs/3.examples/30.vite-trpc.md +335 -0
  146. package/dist/docs/3.examples/31.websocket.md +282 -0
  147. package/dist/docs/3.examples/4.custom-error-handler.md +98 -0
  148. package/dist/docs/3.examples/5.database.md +157 -0
  149. package/dist/docs/3.examples/6.elysia.md +70 -0
  150. package/dist/docs/3.examples/7.express.md +78 -0
  151. package/dist/docs/3.examples/8.fastify.md +79 -0
  152. package/dist/docs/3.examples/9.hello-world.md +68 -0
  153. package/dist/docs/README.md +86 -0
  154. package/dist/docs/index.md +121 -0
  155. package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +8 -0
  156. package/dist/node_modules/@poppinss/dumper/package.json +1 -1
  157. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  158. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  159. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  160. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  161. package/dist/node_modules/cookie-es/package.json +26 -23
  162. package/dist/node_modules/croner/dist/croner.js +1 -1
  163. package/dist/node_modules/croner/package.json +11 -1
  164. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  165. package/dist/node_modules/defu/package.json +33 -28
  166. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  167. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  168. package/dist/node_modules/rendu/package.json +25 -24
  169. package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
  170. package/dist/node_modules/youch/build/index.js +204 -351
  171. package/dist/node_modules/youch/build/public/error_info/script.js +1 -1
  172. package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
  173. package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
  174. package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
  175. package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
  176. package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
  177. package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
  178. package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
  179. package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
  180. package/dist/node_modules/youch/package.json +35 -32
  181. package/dist/presets/_nitro/runtime/nitro-dev.mjs +12 -57
  182. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -0
  183. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -2
  184. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  185. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +3 -1
  186. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  187. package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
  188. package/dist/presets/bun/runtime/bun.mjs +9 -6
  189. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  190. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  191. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  192. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  193. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  194. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  195. package/dist/presets/deno/runtime/deno-server.mjs +9 -6
  196. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  197. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -3
  198. package/dist/presets/netlify/runtime/netlify.mjs +1 -1
  199. package/dist/presets/node/runtime/node-cluster.mjs +5 -4
  200. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  201. package/dist/presets/node/runtime/node-server.mjs +8 -5
  202. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -2
  203. package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
  204. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  205. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  206. package/dist/presets/vercel/runtime/vercel.web.mjs +3 -5
  207. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  208. package/dist/presets/zephyr/runtime/server.mjs +3 -0
  209. package/dist/runtime/internal/app.mjs +12 -11
  210. package/dist/runtime/internal/cache.d.mts +0 -4
  211. package/dist/runtime/internal/cache.mjs +32 -256
  212. package/dist/runtime/internal/context.d.mts +3 -1
  213. package/dist/runtime/internal/context.mjs +1 -9
  214. package/dist/runtime/internal/error/dev.d.mts +5 -4
  215. package/dist/runtime/internal/error/dev.mjs +47 -49
  216. package/dist/runtime/internal/error/hooks.d.mts +1 -1
  217. package/dist/runtime/internal/error/prod.d.mts +2 -5
  218. package/dist/runtime/internal/error/prod.mjs +19 -33
  219. package/dist/runtime/internal/error/utils.d.mts +4 -4
  220. package/dist/runtime/internal/meta.d.mts +1 -1
  221. package/dist/runtime/internal/plugin.d.mts +2 -2
  222. package/dist/runtime/internal/route-rules.d.mts +11 -4
  223. package/dist/runtime/internal/route-rules.mjs +15 -5
  224. package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -2
  225. package/dist/runtime/internal/routes/dev-tasks.mjs +15 -10
  226. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  227. package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
  228. package/dist/runtime/internal/routes/renderer-template.dev.d.mts +2 -1
  229. package/dist/runtime/internal/routes/scalar.mjs +3 -3
  230. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  231. package/dist/runtime/internal/runtime-config.d.mts +1 -1
  232. package/dist/runtime/internal/runtime-config.mjs +2 -2
  233. package/dist/runtime/internal/static.mjs +5 -4
  234. package/dist/runtime/internal/task.d.mts +3 -1
  235. package/dist/runtime/internal/task.mjs +7 -7
  236. package/dist/runtime/internal/vite/dev-entry.mjs +6 -3
  237. package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
  238. package/dist/runtime/meta.d.mts +1 -0
  239. package/dist/runtime/meta.mjs +2 -0
  240. package/dist/runtime/nitro.d.mts +2 -0
  241. package/dist/runtime/nitro.mjs +4 -2
  242. package/dist/runtime/virtual/error-handler.mjs +1 -1
  243. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  244. package/dist/runtime/virtual/server-assets.d.mts +2 -1
  245. package/dist/runtime/virtual/tracing.d.mts +5 -0
  246. package/dist/runtime/virtual/tracing.mjs +1 -0
  247. package/dist/runtime/vite.d.mts +1 -1
  248. package/dist/types/index.d.mts +215 -195
  249. package/dist/types/index.mjs +1 -11
  250. package/dist/vite.d.mts +3 -8
  251. package/dist/vite.mjs +285 -253
  252. package/lib/tsconfig.json +3 -5
  253. package/package.json +97 -80
  254. package/dist/_libs/confbox.mjs +0 -2509
  255. package/dist/_libs/nypm+giget+tinyexec.mjs +0 -3603
  256. package/dist/_libs/rc9+c12+dotenv.mjs +0 -972
  257. package/dist/node_modules/hookable/dist/index.mjs +0 -266
  258. package/dist/node_modules/hookable/package.json +0 -52
  259. package/dist/node_modules/youch/build/chunk-4L7RY2JA.js +0 -42
  260. package/dist/node_modules/youch/build/chunk-7QV3D5YX.js +0 -83
  261. package/dist/node_modules/youch/build/chunk-AUGPHE32.js +0 -39
  262. package/dist/node_modules/youch/build/chunk-CM7DWJNZ.js +0 -44
  263. package/dist/node_modules/youch/build/chunk-EJH674NB.js +0 -223
  264. package/dist/node_modules/youch/build/chunk-OIJ3WD7L.js +0 -81
  265. package/dist/node_modules/youch/build/chunk-P36L72PL.js +0 -87
  266. package/dist/node_modules/youch/build/chunk-PE3GG3TN.js +0 -65
  267. package/dist/node_modules/youch/build/chunk-X53OIOJH.js +0 -70
  268. package/dist/presets/_nitro/runtime/nitro-dev.d.mts +0 -2
  269. package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +0 -3
  270. package/dist/presets/_nitro/runtime/service-worker.d.mts +0 -2
  271. package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +0 -2
  272. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -8
  273. package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +0 -2
  274. package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +0 -3
  275. package/dist/presets/azure/runtime/_utils.d.mts +0 -2
  276. package/dist/presets/azure/runtime/azure-swa.d.mts +0 -5
  277. package/dist/presets/bun/runtime/bun.d.mts +0 -3
  278. package/dist/presets/cloudflare/runtime/_module-handler.d.mts +0 -16
  279. package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +0 -11
  280. package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +0 -3
  281. package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +0 -20
  282. package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +0 -3
  283. package/dist/presets/deno/runtime/deno-deploy.d.mts +0 -5
  284. package/dist/presets/deno/runtime/deno-server.d.mts +0 -3
  285. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -3
  286. package/dist/presets/netlify/runtime/netlify.d.mts +0 -4
  287. package/dist/presets/node/runtime/node-cluster.d.mts +0 -3
  288. package/dist/presets/node/runtime/node-middleware.d.mts +0 -3
  289. package/dist/presets/node/runtime/node-server.d.mts +0 -3
  290. package/dist/presets/standard/runtime/server.d.mts +0 -3
  291. package/dist/presets/stormkit/runtime/stormkit.d.mts +0 -21
  292. package/dist/presets/vercel/runtime/isr.d.mts +0 -2
  293. package/dist/presets/vercel/runtime/vercel.node.d.mts +0 -3
  294. package/dist/presets/vercel/runtime/vercel.web.d.mts +0 -8
  295. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -2
  296. package/dist/presets/zeabur/runtime/zeabur.d.mts +0 -3
  297. package/dist/runtime/internal/vite/node-runner.mjs +0 -359
@@ -0,0 +1,157 @@
1
+ # Database
2
+
3
+ > Built-in database support with SQL template literals.
4
+
5
+ <code-tree>
6
+
7
+ ```ts [nitro.config.ts]
8
+ import { defineConfig } from "nitro";
9
+
10
+ export default defineConfig({
11
+ experimental: {
12
+ database: true,
13
+ tasks: true,
14
+ },
15
+ database: {
16
+ default: { connector: "sqlite" },
17
+ },
18
+ });
19
+ ```
20
+
21
+ ```json [package.json]
22
+ {
23
+ "type": "module",
24
+ "scripts": {
25
+ "dev": "nitro dev",
26
+ "build": "nitro build"
27
+ },
28
+ "devDependencies": {
29
+ "nitro": "latest"
30
+ }
31
+ }
32
+ ```
33
+
34
+ ```ts [server.ts]
35
+ import { defineHandler } from "nitro";
36
+ import { useDatabase } from "nitro/database";
37
+
38
+ export default defineHandler(async () => {
39
+ const db = useDatabase();
40
+
41
+ // Create users table
42
+ await db.sql`DROP TABLE IF EXISTS users`;
43
+ await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
44
+
45
+ // Add a new user
46
+ const userId = String(Math.round(Math.random() * 10_000));
47
+ await db.sql`INSERT INTO users VALUES (${userId}, 'John', 'Doe', '')`;
48
+
49
+ // Query for users
50
+ const { rows } = await db.sql`SELECT * FROM users WHERE id = ${userId}`;
51
+
52
+ return {
53
+ rows,
54
+ };
55
+ });
56
+ ```
57
+
58
+ ```json [tsconfig.json]
59
+ {
60
+ "extends": "nitro/tsconfig"
61
+ }
62
+ ```
63
+
64
+ ```ts [vite.config.ts]
65
+ import { defineConfig } from "vite";
66
+ import { nitro } from "nitro/vite";
67
+
68
+ export default defineConfig({ plugins: [nitro()] });
69
+ ```
70
+
71
+ ```ts [tasks/db/migrate.ts]
72
+ import { defineTask } from "nitro/task";
73
+ import { useDatabase } from "nitro/database";
74
+
75
+ export default defineTask({
76
+ meta: {
77
+ description: "Run database migrations",
78
+ },
79
+ async run() {
80
+ const db = useDatabase();
81
+
82
+ console.log("Running database migrations...");
83
+
84
+ // Create users table
85
+ await db.sql`DROP TABLE IF EXISTS users`;
86
+ await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
87
+
88
+ return {
89
+ result: "Database migrations complete!",
90
+ };
91
+ },
92
+ });
93
+ ```
94
+ </code-tree>
95
+
96
+ Nitro provides a built-in database layer that uses SQL template literals for safe, parameterized queries. This example creates a users table, inserts a record, and queries it back.
97
+
98
+ ## Querying the Database
99
+
100
+ ```ts [server.ts]
101
+ import { defineHandler } from "nitro";
102
+ import { useDatabase } from "nitro/database";
103
+
104
+ export default defineHandler(async () => {
105
+ const db = useDatabase();
106
+
107
+ // Create users table
108
+ await db.sql`DROP TABLE IF EXISTS users`;
109
+ await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
110
+
111
+ // Add a new user
112
+ const userId = String(Math.round(Math.random() * 10_000));
113
+ await db.sql`INSERT INTO users VALUES (${userId}, 'John', 'Doe', '')`;
114
+
115
+ // Query for users
116
+ const { rows } = await db.sql`SELECT * FROM users WHERE id = ${userId}`;
117
+
118
+ return {
119
+ rows,
120
+ };
121
+ });
122
+ ```
123
+
124
+ Retrieve the database instance using `useDatabase()`. The database can be queried using `db.sql`, and variables like `${userId}` are automatically escaped to prevent SQL injection.
125
+
126
+ ## Running Migrations with Tasks
127
+
128
+ Nitro tasks let you run operations outside of request handlers. For database migrations, create a task file in `tasks/` and run it via the CLI. This keeps schema changes separate from your application code.
129
+
130
+ ```ts [tasks/db/migrate.ts]
131
+ import { defineTask } from "nitro/task";
132
+ import { useDatabase } from "nitro/database";
133
+
134
+ export default defineTask({
135
+ meta: {
136
+ description: "Run database migrations",
137
+ },
138
+ async run() {
139
+ const db = useDatabase();
140
+
141
+ console.log("Running database migrations...");
142
+
143
+ // Create users table
144
+ await db.sql`DROP TABLE IF EXISTS users`;
145
+ await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
146
+
147
+ return {
148
+ result: "Database migrations complete!",
149
+ };
150
+ },
151
+ });
152
+ ```
153
+
154
+ ## Learn More
155
+
156
+ - [Database](/docs/database)
157
+ - [Tasks](/docs/tasks)
@@ -0,0 +1,70 @@
1
+ # Elysia
2
+
3
+ > Integrate Elysia with Nitro using the server entry.
4
+
5
+ <code-tree>
6
+
7
+ ```ts [nitro.config.ts]
8
+ import { defineConfig } from "nitro";
9
+
10
+ export default defineConfig({});
11
+ ```
12
+
13
+ ```json [package.json]
14
+ {
15
+ "type": "module",
16
+ "scripts": {
17
+ "build": "nitro build",
18
+ "dev": "nitro dev"
19
+ },
20
+ "devDependencies": {
21
+ "elysia": "^1.4.28",
22
+ "nitro": "latest"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ```ts [server.ts]
28
+ import { Elysia } from "elysia";
29
+
30
+ const app = new Elysia();
31
+
32
+ app.get("/", () => "Hello, Elysia with Nitro!");
33
+
34
+ export default app.compile();
35
+ ```
36
+
37
+ ```json [tsconfig.json]
38
+ {
39
+ "extends": "nitro/tsconfig"
40
+ }
41
+ ```
42
+
43
+ ```ts [vite.config.ts]
44
+ import { defineConfig } from "vite";
45
+ import { nitro } from "nitro/vite";
46
+
47
+ export default defineConfig({ plugins: [nitro()] });
48
+ ```
49
+ </code-tree>
50
+
51
+ ## Server Entry
52
+
53
+ ```ts [server.ts]
54
+ import { Elysia } from "elysia";
55
+
56
+ const app = new Elysia();
57
+
58
+ app.get("/", () => "Hello, Elysia with Nitro!");
59
+
60
+ export default app.compile();
61
+ ```
62
+
63
+ Nitro auto-detects `server.ts` in your project root and uses it as the server entry. The Elysia app handles all incoming requests, giving you full control over routing and middleware.
64
+
65
+ Call `app.compile()` before exporting to optimize the router for production.
66
+
67
+ ## Learn More
68
+
69
+ - [Server Entry](/docs/server-entry)
70
+ - [Elysia Documentation](https://elysiajs.com/)
@@ -0,0 +1,78 @@
1
+ # Express
2
+
3
+ > Integrate Express with Nitro using the server entry.
4
+
5
+ <code-tree>
6
+
7
+ ```ts [nitro.config.ts]
8
+ import { defineConfig } from "nitro";
9
+
10
+ export default defineConfig({});
11
+ ```
12
+
13
+ ```json [package.json]
14
+ {
15
+ "type": "module",
16
+ "scripts": {
17
+ "build": "nitro build",
18
+ "dev": "nitro dev"
19
+ },
20
+ "devDependencies": {
21
+ "@types/express": "^5.0.6",
22
+ "express": "^5.2.1",
23
+ "nitro": "latest"
24
+ }
25
+ }
26
+ ```
27
+
28
+ ```ts [server.node.ts]
29
+ import Express from "express";
30
+
31
+ const app = Express();
32
+
33
+ app.use("/", (_req, res) => {
34
+ res.send("Hello from Express with Nitro!");
35
+ });
36
+
37
+ export default app;
38
+ ```
39
+
40
+ ```json [tsconfig.json]
41
+ {
42
+ "extends": "nitro/tsconfig"
43
+ }
44
+ ```
45
+
46
+ ```ts [vite.config.ts]
47
+ import { defineConfig } from "vite";
48
+ import { nitro } from "nitro/vite";
49
+
50
+ export default defineConfig({ plugins: [nitro()] });
51
+ ```
52
+ </code-tree>
53
+
54
+ ## Server Entry
55
+
56
+ ```ts [server.node.ts]
57
+ import Express from "express";
58
+
59
+ const app = Express();
60
+
61
+ app.use("/", (_req, res) => {
62
+ res.send("Hello from Express with Nitro!");
63
+ });
64
+
65
+ export default app;
66
+ ```
67
+
68
+ Nitro auto-detects `server.node.ts` in your project root and uses it as the server entry. The Express app handles all incoming requests, giving you full control over routing and middleware.
69
+
70
+ <note>
71
+
72
+ The `.node.ts` suffix indicates this entry is Node.js specific and won't work in other runtimes like Cloudflare Workers or Deno.
73
+ </note>
74
+
75
+ ## Learn More
76
+
77
+ - [Server Entry](/docs/server-entry)
78
+ - [Express Documentation](https://expressjs.com/)
@@ -0,0 +1,79 @@
1
+ # Fastify
2
+
3
+ > Integrate Fastify with Nitro using the server entry.
4
+
5
+ <code-tree>
6
+
7
+ ```ts [nitro.config.ts]
8
+ import { defineConfig } from "nitro";
9
+
10
+ export default defineConfig({});
11
+ ```
12
+
13
+ ```json [package.json]
14
+ {
15
+ "type": "module",
16
+ "scripts": {
17
+ "build": "nitro build",
18
+ "dev": "nitro dev"
19
+ },
20
+ "devDependencies": {
21
+ "fastify": "^5.8.4",
22
+ "nitro": "latest"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ```ts [server.node.ts]
28
+ import Fastify from "fastify";
29
+
30
+ const app = Fastify();
31
+
32
+ app.get("/", () => "Hello, Fastify with Nitro!");
33
+
34
+ await app.ready();
35
+
36
+ export default app.routing;
37
+ ```
38
+
39
+ ```json [tsconfig.json]
40
+ {
41
+ "extends": "nitro/tsconfig"
42
+ }
43
+ ```
44
+
45
+ ```ts [vite.config.ts]
46
+ import { defineConfig } from "vite";
47
+ import { nitro } from "nitro/vite";
48
+
49
+ export default defineConfig({ plugins: [nitro()] });
50
+ ```
51
+ </code-tree>
52
+
53
+ ## Server Entry
54
+
55
+ ```ts [server.node.ts]
56
+ import Fastify from "fastify";
57
+
58
+ const app = Fastify();
59
+
60
+ app.get("/", () => "Hello, Fastify with Nitro!");
61
+
62
+ await app.ready();
63
+
64
+ export default app.routing;
65
+ ```
66
+
67
+ Nitro auto-detects `server.node.ts` in your project root and uses it as the server entry.
68
+
69
+ Call `await app.ready()` to initialize all registered plugins before exporting. Export `app.routing` (not `app`) to provide Nitro with the request handler function.
70
+
71
+ <note>
72
+
73
+ The `.node.ts` suffix indicates this entry is Node.js specific and won't work in other runtimes like Cloudflare Workers or Deno.
74
+ </note>
75
+
76
+ ## Learn More
77
+
78
+ - [Server Entry](/docs/server-entry)
79
+ - [Fastify Documentation](https://fastify.dev/)
@@ -0,0 +1,68 @@
1
+ # Hello World
2
+
3
+ > Minimal Nitro server using the web standard fetch handler.
4
+
5
+ <code-tree>
6
+
7
+ ```ts [nitro.config.ts]
8
+ import { defineConfig } from "nitro";
9
+
10
+ export default defineConfig({});
11
+ ```
12
+
13
+ ```json [package.json]
14
+ {
15
+ "type": "module",
16
+ "scripts": {
17
+ "build": "nitro build",
18
+ "dev": "nitro dev",
19
+ "preview": "node .output/server/index.mjs"
20
+ },
21
+ "devDependencies": {
22
+ "nitro": "latest"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ```ts [server.ts]
28
+ export default {
29
+ fetch(req: Request) {
30
+ return new Response("Nitro Works!");
31
+ },
32
+ };
33
+ ```
34
+
35
+ ```json [tsconfig.json]
36
+ {
37
+ "extends": "nitro/tsconfig"
38
+ }
39
+ ```
40
+
41
+ ```ts [vite.config.ts]
42
+ import { defineConfig } from "vite";
43
+ import { nitro } from "nitro/vite";
44
+
45
+ export default defineConfig({ plugins: [nitro()] });
46
+ ```
47
+ </code-tree>
48
+
49
+ The simplest Nitro server. Export an object with a `fetch` method that receives a standard `Request` and returns a `Response`. No frameworks, no abstractions, just the web platform.
50
+
51
+ ## Server Entry
52
+
53
+ ```ts [server.ts]
54
+ export default {
55
+ fetch(req: Request) {
56
+ return new Response("Nitro Works!");
57
+ },
58
+ };
59
+ ```
60
+
61
+ The `fetch` method follows the same signature as Service Workers and Cloudflare Workers. This pattern works across all deployment targets because it uses web standards.
62
+
63
+ Add the Nitro plugin to Vite and it handles the rest: dev server, hot reloading, and production builds.
64
+
65
+ ## Learn More
66
+
67
+ - [Server Entry](/docs/server-entry)
68
+ - [Configuration](/docs/configuration)
@@ -0,0 +1,86 @@
1
+ # Nitro Documentation
2
+
3
+ - [Docs](./0.docs/0.index/index.md)
4
+ - [Introduction](./0.docs/0.index/index.md)
5
+ - [Quick Start](./0.docs/1.quick-start.md)
6
+ - [Renderer](./0.docs/2.renderer.md)
7
+ - [Routing](./0.docs/3.routing.md)
8
+ - [Server Entry](./0.docs/4.server-entry.md)
9
+ - [Cache](./0.docs/5.cache.md)
10
+ - [KV Storage](./0.docs/6.storage.md)
11
+ - [Assets](./0.docs/7.assets.md)
12
+ - [Configuration](./0.docs/8.configuration.md)
13
+ - [Database](./0.docs/9.database.md)
14
+ - [Lifecycle](./0.docs/10.lifecycle.md)
15
+ - [OpenAPI](./0.docs/11.openapi.md)
16
+ - [Plugins](./0.docs/12.plugins.md)
17
+ - [Tasks](./0.docs/13.tasks.md)
18
+ - [WebSocket](./0.docs/14.websocket.md)
19
+ - [Migration Guide](./0.docs/15.migration.md)
20
+ - [Nightly Channel](./0.docs/16.nightly.md)
21
+ - [Deploy](./1.deploy/0.index/index.md)
22
+ - [Deploy](./1.deploy/0.index/index.md)
23
+ - [Node.js](./1.deploy/1.runtimes/0.node.md)
24
+ - [Bun](./1.deploy/1.runtimes/1.bun.md)
25
+ - [Deno](./1.deploy/1.runtimes/2.deno.md)
26
+ - [Alwaysdata](./1.deploy/2.providers/0.alwaysdata.md)
27
+ - [AWS Lambda](./1.deploy/2.providers/1.aws.md)
28
+ - [AWS Amplify](./1.deploy/2.providers/2.aws-amplify.md)
29
+ - [Azure](./1.deploy/2.providers/3.azure.md)
30
+ - [Cleavr](./1.deploy/2.providers/4.cleavr.md)
31
+ - [Cloudflare](./1.deploy/2.providers/5.cloudflare.md)
32
+ - [Deno Deploy](./1.deploy/2.providers/6.deno-deploy.md)
33
+ - [DigitalOcean](./1.deploy/2.providers/7.digitalocean.md)
34
+ - [EdgeOne Pages](./1.deploy/2.providers/8.edgeone.md)
35
+ - [Firebase](./1.deploy/2.providers/9.firebase.md)
36
+ - [Flightcontrol](./1.deploy/2.providers/10.flightcontrol.md)
37
+ - [Genezio](./1.deploy/2.providers/11.genezio.md)
38
+ - [GitHub Pages](./1.deploy/2.providers/12.github-pages.md)
39
+ - [GitLab Pages](./1.deploy/2.providers/13.gitlab-pages.md)
40
+ - [Heroku](./1.deploy/2.providers/14.heroku.md)
41
+ - [IIS](./1.deploy/2.providers/15.iis.md)
42
+ - [Koyeb](./1.deploy/2.providers/16.koyeb.md)
43
+ - [Netlify](./1.deploy/2.providers/17.netlify.md)
44
+ - [Platform.sh](./1.deploy/2.providers/18.platform-sh.md)
45
+ - [Render.com](./1.deploy/2.providers/19.render.md)
46
+ - [StormKit](./1.deploy/2.providers/20.stormkit.md)
47
+ - [Vercel](./1.deploy/2.providers/21.vercel.md)
48
+ - [Zeabur](./1.deploy/2.providers/22.zeabur.md)
49
+ - [Zephyr Cloud](./1.deploy/2.providers/23.zephyr.md)
50
+ - [Zerops](./1.deploy/2.providers/24.zerops.md)
51
+ - [Config](./2.config/0.index/index.md)
52
+ - [Config](./2.config/0.index/index.md)
53
+ - [Examples](./3.examples/0.index/index.md)
54
+ - [Examples](./3.examples/0.index/index.md)
55
+ - [API Routes](./3.examples/1.api-routes.md)
56
+ - [Auto Imports](./3.examples/2.auto-imports.md)
57
+ - [Cached Handler](./3.examples/3.cached-handler.md)
58
+ - [Custom Error Handler](./3.examples/4.custom-error-handler.md)
59
+ - [Database](./3.examples/5.database.md)
60
+ - [Elysia](./3.examples/6.elysia.md)
61
+ - [Express](./3.examples/7.express.md)
62
+ - [Fastify](./3.examples/8.fastify.md)
63
+ - [Hello World](./3.examples/9.hello-world.md)
64
+ - [Hono](./3.examples/10.hono.md)
65
+ - [Import Alias](./3.examples/11.import-alias.md)
66
+ - [Middleware](./3.examples/12.middleware.md)
67
+ - [Mono JSX](./3.examples/13.mono-jsx.md)
68
+ - [Nano JSX](./3.examples/14.nano-jsx.md)
69
+ - [Plugins](./3.examples/15.plugins.md)
70
+ - [Custom Renderer](./3.examples/16.renderer.md)
71
+ - [Runtime Config](./3.examples/17.runtime-config.md)
72
+ - [Server Fetch](./3.examples/18.server-fetch.md)
73
+ - [Shiki](./3.examples/19.shiki.md)
74
+ - [Virtual Routes](./3.examples/20.virtual-routes.md)
75
+ - [Vite Nitro Plugin](./3.examples/21.vite-nitro-plugin.md)
76
+ - [Vite RSC](./3.examples/22.vite-rsc.md)
77
+ - [Vite SSR HTML](./3.examples/23.vite-ssr-html.md)
78
+ - [SSR with Preact](./3.examples/24.vite-ssr-preact.md)
79
+ - [SSR with React](./3.examples/25.vite-ssr-react.md)
80
+ - [SSR with SolidJS](./3.examples/26.vite-ssr-solid.md)
81
+ - [SSR with TanStack Router](./3.examples/27.vite-ssr-tsr-react.md)
82
+ - [SSR with TanStack Start](./3.examples/28.vite-ssr-tss-react.md)
83
+ - [SSR with Vue Router](./3.examples/29.vite-ssr-vue-router.md)
84
+ - [Vite + tRPC](./3.examples/30.vite-trpc.md)
85
+ - [WebSocket](./3.examples/31.websocket.md)
86
+ - [Index](./index.md)
@@ -0,0 +1,121 @@
1
+ <u-page-hero>
2
+
3
+ <code-group>
4
+
5
+ <prose-pre>
6
+
7
+ ```ts
8
+ import { defineConfig } from 'vite'
9
+ import { nitro } from 'nitro/vite'
10
+
11
+ export default defineConfig({
12
+ plugins: [nitro()],
13
+ nitro: {
14
+ serverDir: "./server"
15
+ }
16
+ })
17
+ ```
18
+ </prose-pre>
19
+
20
+ <prose-pre>
21
+
22
+ ```ts
23
+ import { defineConfig } from 'nitro'
24
+
25
+ export default defineConfig({
26
+ preset: "node",
27
+ serverDir: "./server",
28
+ routeRules: {
29
+ "/api/**": { cache: true }
30
+ }
31
+ })
32
+ ```
33
+ </prose-pre>
34
+ </code-group>
35
+
36
+ <hero-background></hero-background>
37
+
38
+ Build /Servers
39
+
40
+ Nitro extends your Vite application with a production-ready server, compatible with any runtime. Add server routes to your application and deploy many hosting platform with a zero-config experience.
41
+
42
+ <app-hero-links></app-hero-links>
43
+ </u-page-hero>
44
+
45
+ <hero-features>
46
+
47
+ </hero-features>
48
+
49
+ <performance-showcase>
50
+
51
+ </performance-showcase>
52
+
53
+ <landing-features>
54
+
55
+ <feature-card>
56
+
57
+ File-system routing
58
+
59
+ Create server routes in the routes/ folder and they are automatically registered. Or bring your own framework — H3, Hono, Elysia, Express — via a server.ts entry.
60
+ </feature-card>
61
+
62
+ <feature-card>
63
+
64
+ Deploy everywhere
65
+
66
+ The same codebase deploys to Node.js, Cloudflare Workers, Deno, Bun, AWS Lambda, Vercel, Netlify, and more — zero config, no vendor lock-in.
67
+ </feature-card>
68
+
69
+ <feature-card>
70
+
71
+ Universal storage
72
+
73
+ Built-in key-value storage abstraction powered by unstorage. Works with filesystem, Redis, Cloudflare KV, and more — same API everywhere.
74
+ </feature-card>
75
+
76
+ <feature-card>
77
+
78
+ Built-in caching
79
+
80
+ Cache route handlers and arbitrary functions with a simple API. Supports multiple storage backends and stale-while-revalidate patterns.
81
+ </feature-card>
82
+
83
+ <feature-card>
84
+
85
+ Web standard server
86
+
87
+ Go full Web standard and pick the library of your choice. Use H3, Hono, Elysia, Express, or the raw fetch API — Nitro handles the rest.
88
+ </feature-card>
89
+
90
+ <feature-card>
91
+
92
+ Universal renderer
93
+
94
+ Use any frontend framework as your renderer. Nitro provides the server layer while your framework handles the UI.
95
+ </feature-card>
96
+
97
+ <feature-card>
98
+
99
+ Server plugins
100
+
101
+ Extend Nitro's runtime behavior with plugins. Hook into lifecycle events, register custom logic, and auto-load from the plugins/ directory.
102
+ </feature-card>
103
+
104
+ <feature-card>
105
+
106
+ Built-in database
107
+
108
+ Lightweight SQL database layer powered by db0. Pre-configured with SQLite out of the box, with support for PostgreSQL, MySQL, and Cloudflare D1.
109
+ </feature-card>
110
+
111
+ <feature-card>
112
+
113
+ Static & server assets
114
+
115
+ Serve public assets directly to clients or bundle server assets for programmatic access. Works seamlessly across all deployment targets.
116
+ </feature-card>
117
+ </landing-features>
118
+
119
+ <page-sponsors>
120
+
121
+ </page-sponsors>
@@ -630,6 +630,14 @@ function createStyleSheet() {
630
630
  padding: 10px 15px;
631
631
  margin: 0;
632
632
  }
633
+ .dumper-dump pre code, .dumper-dump pre code span {
634
+ display: inline;
635
+ margin: 0;
636
+ padding: 0;
637
+ }
638
+ .dumper-toggle {
639
+ padding: 0 !important;
640
+ }
633
641
  .dumper-dump pre samp {
634
642
  position: relative;
635
643
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poppinss/dumper",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Pretty print JavaScript data types in the terminal and the browser",
5
5
  "main": "build/index.js",
6
6
  "type": "module",