Minimum setup for node native module development with VScode

It is difficult to develop node native module without IDE. Because V8 API is difficult to use, complicated, often changed. node-gyp can generate Visual Studio solution file but other IDE is not supported well. I show how to setup writing native module on VScode

Install node headers

Install header files of node.js via node-gyp configure

node header is installed under user cache directory

  • Windows %LOCALAPPDATA%\Cache\node-gyp
  • macOS ~/Library/Caches/node-gyp
  • Linux ~/.cache/node-gyp

Set include paths

Do C/C++: Edit configurations (JSON) via command palette and open c_cpp_properties.json.

Add above header path to includePath list

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${env:HOME}/.cache/node-gyp/12.16.1/include/node" // 12.16.1 is node version, you need to change to your node version
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Screenshot

f:id:syohex:20200405153245g:plain

Enjoy