Franck Freiburger
Franck Freiburger

Reputation: 28518

launch dedicated DevTools for Node.js from command-line

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")

Upvotes: 28

Views: 3573

Answers (3)

nsubhadipta
nsubhadipta

Reputation: 49

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

Upvotes: 0

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

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

Upvotes: 1

Ashok JayaPrakash
Ashok JayaPrakash

Reputation: 2293

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

Upvotes: -2

Related Questions