On macOS, I found (given an install of Node version 16.17.0) that my node_api.h
was stored at ~/.node-gyp/16.17.0/include/node/node_api.h
. So I was able to include it via the path ~/.node-gyp/16.17.0/include/**
.
So, to get proper Intellisense in VS Code, I edited this config file. Quite a few fields were already set up for me by default, but all I changed with regards to this question was to add an extra path to includePath
.
.vscode/c_cpp_properties.json
:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"~/.node-gyp/16.17.0/include/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
You can avoid hard-coding the version by changing the path to:
~/.node-gyp/**
... but be warned that if you have multiple versions of node installed, you'll end up including duplicate headers (and having a bad time). So alternatively, you could manually set up a symlink at ~/.node-gyp/current
that points to whichever version of node you're using, I guess, and set your path as ~/.node-gyp/current/**
. Or just point at one installed version of node arbitrarily and hope that the headers don't change that much between versions..!
C:/Users/<user>/.node-gyp/<version>/include/node
– Keeton