• value {any}
    • Returns: {boolean}

    Returns true if the value is a native External value.

    A native External value is a special type of object that contains a raw C++ pointer (void*) for access from native code, and has no other 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.

    1. #include <js_native_api.h>
    2. #include <stdlib.h>
    3. napi_value result;
    4. static napi_value MyNapi(napi_env env, napi_callback_info info) {
    5. int* raw = (int*) malloc(1024);
    6. napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);
    7. if (status != napi_ok) {
    8. napi_throw_error(env, NULL, "napi_create_external failed");
    9. return NULL;
    10. }
    11. return result;
    12. }
    13. ...
    14. DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
    15. ...
    1. const native = require('napi_addon.node');
    2. const data = native.myNapi();
    3. util.types.isExternal(data); // returns true
    4. util.types.isExternal(0); // returns false
    5. util.types.isExternal(new String('foo')); // returns false

    For further information on napi_create_external, refer to [napi_create_external()][].