docs: Update all examples to use esm modules
See original GitHub issuee.g.
'use strict'
const { createServer } = require('http')
const { Client } = require('undici')
const server = createServer((request, response) => {
response.end('Hello, World!')
})
server.listen(() => {
const client = new Client(`http://localhost:${server.address().port}`)
client.request({
path: '/',
method: 'GET',
}).then(({ body }) => {
body.destroy()
}).catch(error => {
console.error(error) // should print an RequestAbortedError
client.close()
server.close()
})
})
to
import { createServer } from 'http'
import { Client } from 'undici'
import { once } from 'events'
const server = createServer((request, response) => {
response.end('Hello, World!')
})
await once(server, 'listening')
const client = new Client(`http://localhost:${server.address().port}`)
try {
const { body } = await client.request({
path: '/',
method: 'GET',
})
body.destroy()
} catch (err) {
console.error(error) // should print an RequestAbortedError
client.close()
server.close()
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Using ECMAScript modules (ESM) with Node.js
Learn about using ES modules in Node.js today and get a closer look at how you can migrate your codebase to make use...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to support, since the foundation of...
Read more >Using ES Modules (ESM) in Node.js: A Practical Guide (Part 1)
This guide shows you how to use ESM in Node.js, detailing the basics, and also the gotchas that you need to be careful...
Read more >Update documentation examples to use ES module style #6785
I think so, but this shouldn't be an issue anyway. If you're using esm, node will resolve to the esm version of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can I take it up?
Hey @ronag! Do you think we could close this issue now since the PR is merged?