All you have to do is throw your .js and .ts files inside of the ./functions folder of your project and Nhost takes care of deploying your functions as part of a Deployment.

To deploy Nhost Functions, your project needs to be connected to a GitHub repository.

Nhost Functions

  • JavaScript

  • TypeScript

./functions/hello.js
export default (req, res) => {
  res.status(200).send(`Hello ${req.query.name}!`)
}
Folders and filenames prepended with an underscore are not exposed. This is useful, for example, for utility functions that you want to share across multiple functions.

Endpoints

Functions are exposed through HTTP endpoints generated based on the contents of ./functions:

FileHTTP Endpoint
functions/index.jshttps://[subdomain].functions.[region].nhost.run/v1/
functions/users/index.tshttps://[subdomain].functions.[region].nhost.run/v1/users
functions/users/active.tshttps://[subdomain].functions.[region].nhost.run/v1/users/active
functions/my-company.jshttps://[subdomain].functions.[region].nhost.run/v1/my-company
Folders and filenames prepended with an underscore are not exposed. This is useful, for example, for utility functions that you want to share across multiple functions.

Environment Variables

Environment variables are available to your Functions. Both in production and when running Nhost locally using the Nhost CLI.

The same environment variables that are used to configure event triggers can be used to authenticate functions.

Billing

Functions are billed per GB-sec or GB-hour. 1 GB-hour is 3600 GB-seconds.

1 GB-sec is 1 Function with 1GB of RAM running for 1 second. If 1 Function with 1GB of RAM runs for 3600 seconds, that’s the equivalent of 1 GB-hour.

Additional Resources