Field note
What it does
Serverless Functions Overview { res.status(200).send('Hello World!') } ``` ## Routing Endpoints are generated based on the file path relative to `./functions`: | File | HTTP Endpoint | | --------------------------- | ------------------------------------------------------------------ | | `functions/index.js` | `https://[subdomain].functions.[region].nhost.run/v1/` | | `functions/users/index.ts` | `https://[subdomain].functions.[region].nhost.run/v1/users` | | `functions/users/active.ts` | `https://[subdomain].functions.[region].nhost.run/v1/users/active` | | `functions/my-company.js` | `https://[subdomain].functions.[region].nhost.run/v1/my-company` | All HTTP methods (GET, POST, PUT, DELETE, etc.) are routed to the same handler. Use `req.method` to differentiate. ### Directory Conventions - Files and folders prefixed with an **underscore** (`_`) are ignored and not exposed as endpoints. Use this for shared utilities. - `index` files map to the parent directory path. ## Request and Response Functions receive standard Express `Request` and `Response` objects with a few additions: | Property | Description | | ----------------- | -------------------------------------------------- | | `req.method` | HTTP method (GET, POST, etc.) | | `req.headers` | Request headers | | `req.query` | Parsed query string parameters | | `req.body` | Parsed request body (JSON, form data) | | `req.rawBody` | Raw request body as a Buffer | | `req.invocationId`| Unique identifier for this function invocation | The `invocationId` is useful for correlating [logs](/products/functions/logging) across a single invocation. ## Environment Variables The following environment variables are automatically injected into your functions at runtime: | Variable | Description | | --------------------------------- | ---------------------------------------------- | | `NHOST_ADMIN_SECRET` | Admin secret for your project | | `NHOST_WEBHOOK_SECRET` | Webhook secret for your project | | `NHOST_JWT_SECRET` | JWT secret configuration (JSON string) | | `NHOST_SUBDOMAIN` | Project subdomain | | `NHOST_REGION` | Project region | | `NHOST_HASURA_URL` | Internal GraphQL engine URL | | `NHOST_AUTH_URL` | Internal Auth URL | | `NHOST_GRAPHQL_URL` | Internal GraphQL URL | | `NHOST_STORAGE_URL` | Internal Storage URL | | `NHOST_FUNCTIONS_URL` | Internal Functions URL | Any [custom environment variables](/platform/cloud/environment-variables) you define are also available. ## Deployment Functions are deployed automatically when you push to the connected GitHub repository.
Capabilities
Available capabilities
Tags
Tags
No tags filed yet.
Ways to use it
Ways to use it
No integrations filed yet.