doc: add missing setEncoding call in ESM example

Adding `setEncoding()` ensures that the example handles characters
split across chunk boundaries well.

PR-URL: https://github.com/nodejs/node/pull/47558
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Anna Henningsen
2023-04-14 14:53:50 +02:00
committed by GitHub
parent 503d838b1e
commit cad0ae702b

View File

@@ -1058,6 +1058,7 @@ export function load(url, context, nextLoad) {
return new Promise((resolve, reject) => {
get(url, (res) => {
let data = '';
res.setEncoding('utf8');
res.on('data', (chunk) => data += chunk);
res.on('end', () => resolve({
// This example assumes all network-provided JavaScript is ES module