Back to Blog
Product | Platform | Serverless | Functions

Functions: Added support for Node.js 20

26 June 2024
Transparent lines
Banner of Functions: Added support for Node.js 20

Today we are happy to announce you can now chose whether you want to use Node.js 18 or Node.js 20 as your functions runtime.

Doing so is very easy, just select your preferred version in your nhost.toml. For instance, imagine you have the following function in your project


_14
// functions/echo.ts
_14
import { Request, Response } from 'express'
_14
import process from 'process'
_14
_14
export default (req: Request, res: Response) => {
_14
res.status(201).json(
_14
{
_14
headers: req.headers,
_14
query: req.query,
_14
node: process.version, // return node version
_14
arch: process.arch,
_14
},
_14
)
_14
}

We can use Node.js 18 by ensuring the following configuration is in our nhost.toml:


_10
[functions.node]
_10
version = 18

If we now start the CLI with nhost up or push to our deployment branch we should be able to verify the runtime by invoking the function:


_10
$ curl -s https://local.functions.nhost.run/v1/echo | jq .node
_10
"v18.20.3"

To use Node.js 20, just set the correct version:


_10
[functions.node]
_10
version = 20

And invoke the function again:


_10
$ curl -s https://local.functions.nhost.run/v1/echo | jq .node
_10
"v20.15.0"

While a small improvement, we hope this new addition will help you homogenize your runtime environments and simplify your setups.

For more details don't hesitate to check our documentation.

Share this post

Twitter LogoLinkedIn LogoFacebook Logo