Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add ESM usage example in Getting Started #5294

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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