Search code examples
node.jsdebuggingcmakeclion

How do you debug a Node.js addon built with CMake.js?


I want to be able to step though my C++ code for a Node.js addon that I am making. I understand that CMake.js has the --debug option, but there is no documentation about it.

I am using the node-addon-api module, in CLion.


Solution

  • After months of blind debugging though the use of Errors to print variables, I have finally figured out how to attach the CLion debugger to a Node.js addon.

    1. Create a new CMake Application configuration.
    2. Fill in these fields:
      • Target: Your project
      • Executable: The Node binary (On Unix run which node or where.exe node on Windows to get the path)
      • Program arguments: Path to your JS file
      • Working directory: The directory where the JS file is located
      • Before launch: Build
    3. Start this configuration in debug mode.