nodejs logging library code example
Example: node log centered
// Center text horizontally
function logXCentered(s) {
console.log(' '.repeat(process.stdout.columns / 2 - s.length / 2) + s);
}
logXCentered('This text is centered horizontally.');
// Center text both, horizontally and vertically
function logCentered(s) {
console.log(
'\n'.repeat(process.stdout.rows / 2) +
' '.repeat(process.stdout.columns / 2 - s.length / 2) +
s +
'\n'.repeat(process.stdout.rows / 2 - 1)
);
}
logCentered('This text is centered.');