Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: Take --debug-port into account
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Feb 23, 2017
1 parent 37cc9b7 commit 054d4b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/_inspect.js
Expand Up @@ -41,7 +41,16 @@ const [ InspectClient, createRepl ] =

const debuglog = util.debuglog('inspect');

exports.port = 9229;
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)-port=(\d+)$/;
function getDefaultPort() {
for (const arg of process.execArgv) {
const match = arg.match(DEBUG_PORT_PATTERN);
if (match) {
return +match[1];
}
}
return 9229;
}

function runScript(script, scriptArgs, inspectPort, childPrint) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -228,7 +237,7 @@ class NodeInspector {

function parseArgv([target, ...args]) {
let host = '127.0.0.1';
let port = exports.port;
let port = getDefaultPort();
let isRemote = false;
let script = target;
let scriptArgs = args;
Expand Down

0 comments on commit 054d4b1

Please sign in to comment.