1# External Buffer
2
3**Some runtimes other than Node.js have dropped support for external buffers**.
4On runtimes other than Node.js, node-api methods may return
5`napi_no_external_buffers_allowed` to indicate that external
6buffers are not supported. One such runtime is Electron as
7described in this issue
8[electron/issues/35801](electron/electron/issues/35801).
9
10In order to maintain broadest compatibility with all runtimes,
11you may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before
12includes for the node-api and node-addon-api headers. Doing so will hide the
13functions that create external buffers. This will ensure a compilation error
14occurs if you accidentally use one of these methods.
15
16In node-addon-api, the `Napi::Buffer::NewOrCopy` provides a convenient way to
17create an external buffer, or allocate a new buffer and copy the data when the
18external buffer is not supported.
19