node js logging code example
Example 1: javascript console log
console.log('string');
Example 2: node js console log
console.log("hello world");
Example 3: node log centered
function logXCentered(s) {
console.log(' '.repeat(process.stdout.columns / 2 - s.length / 2) + s);
}
logXCentered('This text is centered horizontally.');
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.');