Yaroslav Wally
Yaroslav Wally

Reputation: 78

Can I see the value of variables at any moment of Node JS app execution?

Can I see the value of variables at any moment of Node JS app execution? Like VSC debugger do (screen), but I can see values only when breakpoint hits and code stops. I would like to see it in dynamic, imagine this like I trigger some button and can see what variables are in this moment of time.

Any information would be appreciated including what terms should I use for googling to figure it out. (Of course, there is console.log, but I'm looking For some advanced functionality )

Upvotes: 0

Views: 829

Answers (1)

Tembero
Tembero

Reputation: 407

This is not the best method but it works:

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function startListening() {
    rl.question("", (answer) => {
        eval(`console.log(${answer})`);
    

        startListening();
    });
}
startListening();

Add this to the file you want to "debug".

Now just type the variable name to the console you want to get.

Upvotes: 1

Related Questions