Skip to content

Commit

Permalink
docs: add ESM usage example in Getting Started (#5294)
Browse files Browse the repository at this point in the history
  • Loading branch information
atilagulers committed Jan 28, 2024
1 parent d214201 commit 62f564d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/Guides/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ fastify.listen({ port: 3000 }, function (err, address) {
})
```

> If you are using ECMAScript Modules (ESM) in your project, be sure to
> include "type": "module" in your package.json.
>```js
>{
> "type": "module"
>}
>```
Do you prefer to use `async/await`? Fastify supports it out-of-the-box.

```js
Expand Down Expand Up @@ -172,6 +180,7 @@ fastify.listen({ port: 3000 }, function (err, address) {
})
```


```js
// our-first-route.js

Expand All @@ -186,6 +195,10 @@ async function routes (fastify, options) {
})
}

//ESM
export default routes;

// CommonJs
module.exports = routes
```
In this example, we used the `register` API, which is the core of the Fastify
Expand Down

0 comments on commit 62f564d

Please sign in to comment.