2

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
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • I guess if you re using Karma, Jasmine ... you should have an already full debugger tool. But if you want to add some Aliases and use the syntax as your example, may be it should be possible by adding bashrc or doing an Export. –  Oct 21 '17 at 07:53

2 Answers2

1

I am not sure what you are trying to do. If you are using Bash, his line introduces a nodeinsp "executable".

alias nodeinsp="node --inspect"

Eugene
  • 9,242
  • 2
  • 30
  • 29
  • yeah I need an env variable because this is for a library so it needs to be more generic than that – Alexander Mills Oct 25 '17 at 01:02
  • 1
    @AlexanderMills you can also enable inspector by calling `process._debugProcess(pid)` from another Node.js instance. – Eugene Oct 25 '17 at 16:46
  • where did you find that info by the way? – Alexander Mills Oct 25 '17 at 17:26
  • @AlexanderMills I wrote it ;) It is undocumented and kinda legacy API. But there are some important use cases so it will stay there for the time being. – Eugene Nov 02 '17 at 17:14
  • I am actually looking for a way to inspect google chrome from a node.js process, any idea if that's possible? – Alexander Mills Nov 02 '17 at 17:27
  • 1
    Sure. All you need is a WS connection to the Chrome browser (e.g. you need to run the Chrome with the `--remote-debugging-port=9222` flag). Then you send the inspector commands and read the replies. https://github.com/eugeneo/node-targets-discovery - this is some test code for accessing Node instances, should work with Chrome just as good. – Eugene Nov 02 '17 at 22:07
  • https://github.com/eugeneo/node-restarter/blob/master/restarter.js - another example. – Eugene Nov 02 '17 at 22:08
  • Are you working on React Native or something? Why do you know so much about Node.js if you are working on Android at Google? :) – Alexander Mills Nov 02 '17 at 22:52
  • I am looking for a contributor to an OSS project who is good with Node.js – Alexander Mills Nov 02 '17 at 22:53
  • at the moment, working on getting tests to run in the browser, and to put the browser in a debugging environment so the developer can debug tests running the browser. both chrome and firefox. I don't think current test runners like Karma do a good job of this, so could be a big win. – Alexander Mills Nov 02 '17 at 22:54
1
#! /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

milahu
  • 2,447
  • 1
  • 18
  • 25