Node.js native addons: where is node_api.h located?

Viewed 8344

I'm trying to create a native addon for Node.js and when I include

#include <napi.h>

The Intelli Sense of VS Code says that it cannot detect where node_api.h is located (it's included by napi.h).

node-gyp build works well and it compiles. But I do not understand where is that header in the system and where node-gyp gets it from? I need to add the path to the Intelli Sense options and to better understand the process of building in general.

I'm playing with this code example.

3 Answers

I have run a full search on disk C (I'm on Windows 10), and found out that the header file node_api.h is located in

C:\Users\<UserName>\AppData\Local\node-gyp\Cache\<NodeVersion>\include\node

as well as other headers like v8.h.

If you delete that folder, node-gyp build no longer works. node-gyp configure downloads all headers again and restores the above mentioned folder.

Are you using extension ms-vscode.cpptools by Microsoft? Then you should just add the path for the header files used by napi to your include path in VSCode: Move your cursor over the include line with the error -> chose "Quick Fix" -> there should be an option for setting include path options (exact naming is language specific) -> new tab opens, add the path under "include path"

The header files are located in appdata as described by RussCoder.

Alternatively see: https://code.visualstudio.com/docs/cpp/customize-default-settings-cpp

Related