简体   繁体   中英

Can I execute nodejs javascript scripts in chrome devtools?

Is it possible to use chrome devtools to execute the terminal command node myfile.js , so the chrome console would output all console.log s from my code? I have got some terminal plugin installed in my IDE and I use some keyboard shortcuts when I want to run this command on my files, to get my logs immediately (like when running html+js in the browser) but it prints out just plain text. Chrome can recognize the output data type and structurize it well (arrays, objects) , what is really cool.

I've already tried out node inspect-brk but its purpose seems to be quite different than just printing out my logs.

UPDATE:

I've found very interesting link with npm modules that do what I mean.

I have alredy tested node-monkey but it does not work on my Windows, but iron-node works great and I can run my .js files with iron-node file.js command and get all console.log s in Chrome devtools!

run your file with

node --inspect <your file name>.js

and then type in chrome

chrome://inspect

See https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js for reference

--inspect-brk is used for breakpoint purposes, with that flag the debugger is ready to run your code but is expecting the developer to add something before it begins to run your script. There is a play button at the top corner of the chrome devtools debugger, and if there are no other breakpoints or debugger; statments in your code it will run as it would run or your workstation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM