diff --git a/docs/content/1.guide/6.utils.md b/docs/content/1.guide/6.utils.md new file mode 100644 index 0000000000..17dcdb1686 --- /dev/null +++ b/docs/content/1.guide/6.utils.md @@ -0,0 +1,27 @@ +--- +title: Utils +icon: ri:tools-line +--- + +# Utils + +Nitro helps you to stay organized allowing you to take advantage of the [`auto-imports`](auto-imports.md) feature. + +Every export in the `utils` directory and its subdirectories will become available globally in your application. + +## Example + +Create a `utils/sum.ts` file where a function `useSum` is exported: + +```ts [utils/sum.ts] +export function useSum(a: number, b: number) { return a + b } +``` + +Use it in your `routes/index.ts` file without importing it: + +```ts [routes/index.ts] +export default defineEventHandler(() => { + const sum = useSum(1, 2) // auto-imported + return { sum } +}) +```