Skip to content
Browse files

doc: add an example for util.types.isExternal

added usage example for util.types.isExternal
which was missing owing to the complexity.
Used a combination of n-api and js to demonstrate
usage of the api.

PR-URL: #31173
Fixes: #20604
Reviewed-By: Ruben Bridgewater <>
Reviewed-By: Anto Aravinth <>
Reviewed-By: Anna Henningsen <>
Reviewed-By: Rich Trott <>
  • Loading branch information
HarshithaKP authored and BridgeAR committed Jan 3, 2020
1 parent a2c4244 commit f4a4a1a63c7ceba77a0178b4af6068abcadba41f
Showing with 30 additions and 0 deletions.
  1. +30 −0 doc/api/
@@ -1399,6 +1399,35 @@ properties. Such objects are created either by Node.js internals or native
addons. In JavaScript, they are [frozen][`Object.freeze()`] objects with a
`null` prototype.

#include <js_native_api.h>
#include <stdlib.h>
napi_value result;
static napi_value MyNapi(napi_env env, napi_callback_info info) {
int* raw = (int*) malloc(1024);
napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);
if (status != napi_ok) {
napi_throw_error(env, NULL, "napi_create_external failed");
return NULL;
return result;
const native = require('napi_addon.node');
const data = native.myNapi();
util.types.isExternal(data); // returns true
util.types.isExternal(0); // returns false
util.types.isExternal(new String('foo')); // returns false

For further information on `napi_create_external`, refer to

### `util.types.isFloat32Array(value)`
<!-- YAML
added: v10.0.0
@@ -2358,5 +2387,6 @@ util.log('Timestamped message.');
[default sort]:
[global symbol registry]:
[list of deprecated APIS]: deprecations.html#deprecations_list_of_deprecated_apis
[`napi_create_external()`]: n-api.html#n_api_napi_create_external
[semantically incompatible]:
[util.inspect.custom]: #util_util_inspect_custom

0 comments on commit f4a4a1a

Please sign in to comment.
You can’t perform that action at this time.