question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs: Update all examples to use esm modules

See original GitHub issue

e.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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hionnodecommented, Jun 30, 2021

Can I take it up?

0reactions
joaopedrocamposcommented, Jul 10, 2021

Hey @ronag! Do you think we could close this issue now since the PR is merged?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found