'Prompts doesn't show question with bunyan in nodejs until I answer it
I have an application that must generate logs and also receive input from the users via CLI.
I'm currently using bunyan to generate the logs and output them in the console. I'm using prompts to get the user input via questions.
As I'm using bunyan, I must run the script with the following command:
node script.js | node_modules/.bin/bunyan
The problem is: if I create a single line question i.e. with either text, password, confirm, etc, the question doesn't appear in the CLI until I answer the question, which totally messes up with the purpose of the question lib.
Example code (I'm running NodeJS 14):
import prompts from 'prompts'
await prompts({
type: 'text',
name: 'value',
message: 'question'
})
When I redirect the output to a file, I see the prompts lib prints some ANSI escape chars, which is probably why bunyan doesn't print them properly until I answer the question, but I don't know how to solve it.
When I run this command:
node script.js > output.txt
I get this output in the output.txt file (before answering the question):
\x1B[2K\x1B[1G\x1B[36m?\x1B[39m \x1B[1mquestion\x1B[22m \x1B[90m›\x1B[39m \x1B7\x1B8
(Being \x1B the ESCAPE char, decimal code 27)
How can I fix this? How can I use prompts lib with bunyan?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
