(No idea how to put the problem into a fitting title so if you have an idea please tell me so I can change it)
So I am new to javascript/nodejs and am writing a program that currently should only wait until I have pressed a key a defined number of times and then it should simply give me the clicks per second I made.
var startTime = performance.now();
var presses = 0;
process.stdin.on('keypress', (chunk, key) => {
if (key && key.name == 'q'){
presses++;
}
if (presses >= maxPress){
var endTime = performance.now();
console.log(endTime-startTime);
process.exit();
}
});
const cps = presses / (endTime-startTime);
console.log(cps);
Before process.exit() is called it already tells me that endTime is not defined for the calculation const cps = presses / (endTime-startTime);. From how I understand it the process.stdin.on basically runs alongside the program until it's exited but is there any way to only have the program "advance" after the process is exited?