[英]NodeJS Express Command Line Interaction
运行Express应用程序时,是否可以通过命令行与浏览器控制台类似的方式与其JS环境进行交互?
例如,说Express正在运行,我想通过使用普通js将变量打印到cli来抽查变量。 因此,我将输入以下内容:
<terminal command> console.log( variableToPrint );
某种程度上,您可以使用一个名为“ Debugger”的程序并根据需要打印每个变量值,即使在broser中,也可以执行以下命令:
节点--inspect-brk index.js
然后转到网址chrome://inspect
中的chrome broser。 如果只想在不使用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
有关更多信息,请查看调试器的官方信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.