Skip to content

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 deployment
  • An Nhost project connected to a GitHub repository
  • The Nhost CLI installed for local development

Place a .js or .ts file inside the ./functions directory of your project:

./functions/hello.js
export default (req, res) => {
res.status(200).send(`Hello ${req.query.name}!`)
}

Start the Nhost CLI and call your function:

Terminal window
curl https://local.functions.local.nhost.run/v1/hello?name=World

Push your code to the connected GitHub repository. Nhost automatically deploys your functions as part of a Deployment.

A more complete example that returns request metadata:

./functions/echo.ts
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,
})
}