Skip to content

Commit 62f564d

Browse files
authored
docs: add ESM usage example in Getting Started (fastify#5294)
1 parent d214201 commit 62f564d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/Guides/Getting-Started.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ fastify.listen({ port: 3000 }, function (err, address) {
5555
})
5656
```
5757

58+
> If you are using ECMAScript Modules (ESM) in your project, be sure to
59+
> include "type": "module" in your package.json.
60+
>```js
61+
>{
62+
> "type": "module"
63+
>}
64+
>```
65+
5866
Do you prefer to use `async/await`? Fastify supports it out-of-the-box.
5967
6068
```js
@@ -172,6 +180,7 @@ fastify.listen({ port: 3000 }, function (err, address) {
172180
})
173181
```
174182

183+
175184
```js
176185
// our-first-route.js
177186

@@ -186,6 +195,10 @@ async function routes (fastify, options) {
186195
})
187196
}
188197

198+
//ESM
199+
export default routes;
200+
201+
// CommonJs
189202
module.exports = routes
190203
```
191204
In this example, we used the `register` API, which is the core of the Fastify

0 commit comments

Comments
 (0)