# How to use ES modules in Netlify functions

> Learn how to use ES modules in Netlify functions: add type module to package.json, switch to export async function handler, and return instead of callback.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-02-11 | Topics: [Services](https://flaviocopes.com/tags/services/) | Canonical: https://flaviocopes.com/how-to-use-es-modules-in-netlify-functions/

Add:

```javascript
"type": "module",
```

To the repository’s root level `package.json` file.

Now instead of 

```javascript
exports.handler = async (event, context, callback) => {

}
```

use this:

```javascript
export async function handler(event, context) {

}
```

And any time you used 

```javascript
callback(null, {
  statusCode: 200,
  body: html,
})
```

Now use

```javascript
return {
  statusCode: 200,
  body: html,
}
```
