Getting Started
Create your first serverless function as an HTTP endpoint, test it locally with the Nhost CLI, and deploy it via GitHub.
serverless functions getting started TypeScript JavaScript HTTP endpoints deploymentPrerequisites
Section titled “Prerequisites”- An Nhost project connected to a GitHub repository
- The Nhost CLI installed for local development
Create a Function
Section titled “Create a Function”Place a .js or .ts file inside the ./functions directory of your project:
export default (req, res) => { res.status(200).send(`Hello ${req.query.name}!`)}import type { Request, Response } from 'express'
export default (req: Request, res: Response) => { res.status(200).send(`Hello ${req.query.name}!`)}Test Locally
Section titled “Test Locally”Start the Nhost CLI and call your function:
curl https://local.functions.local.nhost.run/v1/hello?name=WorldDeploy
Section titled “Deploy”Push your code to the connected GitHub repository. Nhost automatically deploys your functions as part of a Deployment.
Echo Example
Section titled “Echo Example”A more complete example that returns request metadata:
import process from 'node:process'import type { Request, Response } from 'express'
export default (req: Request, res: Response) => { res.status(200).json({ headers: req.headers, query: req.query, node: process.version, arch: process.arch, invocationId: req.invocationId, })}