node.jsnode-inspectorblink-developer-tools

Initiate node --inspect / --debug-brk with environment variable


I have been debugging and inspecting with node-inspector with Node.js for a long time, but I have never seen any documentation that allows you to start the debugging environment with an environment variable.

Does anyone know if I can do this:

node --inspect-brk foo.js
node --debug-brk foo.js

using an env variable instead? something like:

NODE_INSPECT=yes node foo.js
NODE_DEBUG_BRK=yes node foo.js

Solution

  • #! /bin/sh
    NODE_OPTIONS='--inspect-brk' node foo.js
    

    example use in package.json

    {
      "scripts": {
        "debug": "cross-env NODE_OPTIONS='--inspect-brk' jest --runInBand"
      }
    }
    

    see also: https://github.com/nodejs/help/issues/910