简体   繁体   English

带有日志记录的nodejs交互式控制台

[英]nodejs interactive console with logging

I have a nodeJS app that currently prints to console during various events and things of that nature. 我有一个nodeJS应用程序,该应用程序当前可以在各种事件和此类事件中打印到控制台。

I'm looking to maintain that logging functionality, while also giving the user the ability to send input and commands. 我希望保持该日志记录功能,同时还使用户能够发送输入和命令。 Kind of like this: 有点像这样:

Some logs
Some other logs
Even more logging
an unholy amount of gibberish
/\ Prints on this line and shifts the other lines up /\
> prompt

I'm aware you can get user input in a synchronous fashion, where the program would wait until the user input is submitted, but would it be possible to do it like this? 我知道您可以以同步方式获取用户输入,该程序将等到提交用户输入后,但是是否可以这样做呢?

Here are two possible options: 这是两个可能的选项:

prompt 提示

An easy to use library to build prompts 一个易于使用的库来生成提示

https://www.npmjs.com/package/prompt https://www.npmjs.com/package/prompt

readline 的ReadLine

If you want to build your own code you can manually read the inputs 如果要构建自己的代码,则可以手动读取输入

https://nodejs.org/api/readline.html https://nodejs.org/api/readline.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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