launch dedicated DevTools for Node.js from command-line
Asked Answered
T

3

28

I wondering how to launch "Open dedicated DevTools for Node" directly from the (windows or linux) command-line, without using chrome://inspect url then Open dedicated DevTools for Node button ?

My aim is to automatically run debugger for node.js:

launchDedicatedDevToolsForNode();
require('inspector').open(null, null, true); // sync
debugger;

note:
The underlying command, just behind the click handler of "Open dedicated DevTools for Node" link is:

chrome.send("open-node-frontend")
Timisoara answered 17/5, 2018 at 13:27 Comment(2)
Check out this answer #12213004Brock
unfortunately, question 12212504 is not about node.jsTimisoara
V
0

You have to write your extension on chrome and run the command there

chrome.send("open-node-frontend")

Volley answered 22/1, 2020 at 1:39 Comment(0)
A
0

Start your Node.js application with the --inspect flag:

node --inspect your-script.js

other then (another Method) you use to automate the process of opening the dedicated DevTools for Node.js, you can use the chrome-remote-interface NPM package to communicate with the Chrome instance and open the Node.js DevTools

Adversative answered 15/7 at 6:29 Comment(0)
B
-2

Chrome provides argument --auto-open-devtools-for-tabs to open the developer tools via cli.

Inorder to run dedicated dev tools via node.js process, Use child_process execFile() method. Check out the following snippet.

const execFile = require('child_process').execFileSync;

function launchChrome(path, hostUrl) {
    try {
        let args = [];
        args.push(hostUrl);
        args.push('--auto-open-devtools-for-tabs'); 
        execFile(path, args);
    } catch (error) {
        console.log(error)
    }
}

//launchChrome(`C:/Program Files (x86)/Google/Chrome/Application/chrome.exe`, '127.0.0.1:8000');

Note: Tested and working in Windows

Brock answered 17/5, 2018 at 17:29 Comment(4)
Your answer is for opening "web" devTools, my aim is to open "dedicated DevTools for Node" to debug the node.js programTimisoara
Just for understanding, VS Code and Webstorm already having debug mode right. What is the differnce between them and "dedicated DevTools for Node" ?Brock
You can open devTools to debug the web page (F12) and you can open devTools to debug running node.js programs (chrome://inspect then click "Open dedicated DevTools for Node"Timisoara
Hey @FranckFreiburger chrome://inspect then click "Open dedicated DevTools for Node" -> Did you find a quicker way to do this?Semibreve

© 2022 - 2024 — McMap. All rights reserved.