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


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

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