0
当运行一个Express应用程序,是否有可能以类似的方式作为浏览器的控制台通过命令行的JS环境进行交互?快速的NodeJS命令行交互
例如,假设快速运行,我想他们打印到使用正常的js CLI来抽查变量。所以我输入类似:
<terminal command> console.log(variableToPrint);
当运行一个Express应用程序,是否有可能以类似的方式作为浏览器的控制台通过命令行的JS环境进行交互?快速的NodeJS命令行交互
例如,假设快速运行,我想他们打印到使用正常的js CLI来抽查变量。所以我输入类似:
<terminal command> console.log(variableToPrint);
的,你甚至可以在broser,只要你想使用一个名为“调试”和打印每个变量值的程序,执行此命令类:
node --inspect-brk index.js
然后去url中的你的chrome broser:chrome://inspect
。如果你只是想用命令行没有broser,运行这个文件,下一个命令调试器:
// myscript.js
global.x = 5;
setTimeout(() => {
debugger;
console.log('world');
}, 1000);
console.log('hello');
$节点检查myscript.js
< Debugger listening on ws://127.0.0.1:9229/80e7a814-7cd3-49fb-921a-2e02228cd5ba
< For help see https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in myscript.js:1
> 1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
3 debugger;
debug> cont
< hello
break in myscript.js:3
1 (function (exports, require, module, __filename, __dirname) { global.x = 5;
2 setTimeout(() => {
> 3 debugger;
4 console.log('world');
5 }, 1000);
debug> next
break in myscript.js:4
2 setTimeout(() => {
3 debugger;
> 4 console.log('world');
5 }, 1000);
6 console.log('hello');
debug> repl
Press Ctrl + C to leave debug repl
> x
5
> 2+2
4
debug> next
< world
break in myscript.js:5
3 debugger;
4 console.log('world');
> 5 }, 1000);
6 console.log('hello');
7
debug> .exit
获得进一步的信息检查debuggers official information