doc: use mjs/cjs blocks for callbackify null reason example

PR-URL: https://github.com/nodejs/node/pull/62884
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Daijiro Wachi authored and GitHub committed 2026-04-29 15:40:48 +02:00
1 parent 4a32c00fb8
commit 74c6f85042
1 file changed
+18 -1
+18 -1
View File
@@ -76,7 +76,24 @@ wrapped function rejects a `Promise` with a falsy value as a reason, the value
is wrapped in an `Error` with the original value stored in a field named
`reason`.
```js
```mjs
import util from 'node:util';
function fn() {
return Promise.reject(null);
}
const callbackFunction = util.callbackify(fn);
callbackFunction((err, ret) => {
// When the Promise was rejected with `null` it is wrapped with an Error and
// the original value is stored in `reason`.
err && Object.hasOwn(err, 'reason') && err.reason === null; // true
});
```
```cjs
const util = require('node:util');
function fn() {
return Promise.reject(null);
}