Run Node.js 14 in Azure Functions

Published 03-10-2021 08:50 AM 5,203 Views
Microsoft

The Node.js 14 runtime for Azure Functions is now generally available. It is the latest long-term supported (LTS) version of Node.js. In your functions, you can take advantage of new features in Node.js 14, including:

 

 

ECMAScript modules (preview)

 

In addition to CommonJS modules, you have the option to use ECMAScript modules (ES modules) in Node.js 14. ES modules are now the official standard format for modules in Node.js.

 

To write Azure Functions in ES modules format, change your function’s file extension to .mjs. You can then use ES modules import and export statements in your code.

 

// index.mjs

import { getClient } from "durable-functions";

export default async function (context, req) {
    const client = getClient(context);
    const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
    return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};

 

As ECMAScript modules are currently in “experimental” status in Node.js 14, they are supported in Azure Functions as a preview feature. To learn more, check out our documentation.

 

Migrate your Azure Functions to Node.js 14

 

Node.js has a published release schedule. Update your function apps to Node.js 14 to ensure you’re on the latest long term supported version.

 

When you run Azure Functions locally, it uses the default version of Node.js on your machine. Download and install Node.js 14. While Node.js is highly compatible with earlier versions, make sure to test your app locally and in Azure. To change a function app’s Node.js version in Azure, see the Azure Functions Node.js Developer Guide.

 

 

Co-Authors
Version history
Last update:
‎Mar 09 2021 05:07 PM
Updated by: