Day 4 Console Module In Node.js

本文详细介绍了Node.js中的Console模块,包括console.log()的各种变体、创建新的console、console.clear()、console.count()及其重置、console.error()、console.time()和console.timeEnd()以及console.warn()的使用方法,是Node.js调试和日志记录的重要工具。
摘要由CSDN通过智能技术生成

30 Days of Node

在这里插入图片描述

Inside this article!

  1. Introduction
  2. Console and its types
  3. New Console
  4. Clear Console
  5. Count console
  6. Count reset console
  7. Console error
  8. Console time
  9. Console Warn
  10. Summary
  11. Repository

Introduction to console

The console module provides us with debugging console similar to javascript console mechanism web browsers provide us. It exports two components :

  1. console class : It includes methods such as console.log(), console.warn(), console.error()which we can use to write to node.js streams.
  2. Global console instance : This method is configured to write on process.stderr, process.stdout()and it can be used without exclusively calling the module require('console').

console.log() and all its variations

console.log()is used to print to stdoutwith a newline. We can pass multiple arguments. Let’s see the different variations of console.login the example given below :

// console.log().js
// using ' ' to print
console.log('1: hello world!');
// using " " to print
console.log("2: This will also work!");

const str = 'nodejsera';

const val = 25;

// printing a string
console.log(str);	

// printing a variable and replacing the 
// value of variable in place of %d
console.log('4: Value of val is: %d', val);

// replacing a string in place of %s
console.log('5: %s', 'this will be printed after 5');

// concatinating in console
console.log("6: str = " + str);

The Output is:

1: hello world!
2: This will also work!
nodejsera
4: Value of val is: 25
5: this will be printed after 5
6: str = nodejsera

Create a new console

Creating a new console where stdout</

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值