1.console.dir()查看对象属性
console.dir(123);
console.dir("abc");
console.dir({"abc":123});
console.dir(1+2*3+1);
console.dir(console);
2.查看当前调用栈情况 concole.trace()
console.trace();
console.trace('start');
var fs = require('fs');
var file = './app.py';
var encoding = 'UTF-8';
fs.readFile(file,encoding,function(err,data){
console.trace("fs-start");
if(err){
// console.error("error-\n %s",err);
// console.warn("warn- \n %s",err);
}else{
// console.log(data);
}
console.trace("fs-end");
});
console.trace("end");
3.读取控制台输入的信息 作为参数 给程序 readline模块
var readline = require('readline');
var rl = readline.createInterface({
input:process.stdin,
output:process.stdout
});
rl.question("your name?",function(answer){
console.log("My name is",answer);
rl.close();
});
rl.question("How old are you?",function(answer){
console.log("Im",answer);
rl.close();
})
4.打开文件,如果文件不存在,重定向标准错误输出流
var fs = require('fs');
var file = './app.py';
var encoding = 'UTF-8';
fs.readFile(file,encoding,function(err,data){
if(err){
console.error("error-\n %s",err);
console.warn("warn- \n %s",err);
}else{
console.log(data);
}
});