info.txt(1代表重定向标准输出流);//这个时候会在app.js的同级目录下看到一个info.txt文件,里面还有"log信息". //二"> 跳转到主内容
趣航编程网 - 趣学编程,启航技术之路!

node.js中的console用法总结_node.js

复制代码代码如下://建立app.js页面// 一:页面代码console.log("log信息");//在页面中执行(node app.js)这个文件会在控制台中看到log信息:"log信息"//换个方式执行:node app.js 1>info.txt(1代表重定向标准输出流);//这个时候会在app.js的同级目录下看到一个info.txt文件,里面还有"log信息".

//二:依次序输出所有字符串console.log("%s","first","second");//输出结果:first second//三.将对象转换为普通字符串后执行console.log("%s","guoyansi",{name:"思思博士"});//输出结果:guoyansi { name: '思思博士' }//四://将字符串作为数值进行转换console.log("%d","25.6");//输出结果:25.6 console.log("%d","guoyansi");//输出结果:guoyansi//五  输出% console.log("%%");//输出结果:% console.log("%%","gys");//输出结果:% gys//六 将console.error信息输出到文件中去//页面代码:console.error("guoyansi is error");//利用node app.js 2>err.txt启动这个页面//会在同级目录下多一个err.txt文件.文件里面还有"guoyansi is error"//七 直接在命令行启动一个并不存在的文件javascript.js,这样:// node javascript.js 2>info.txt//输出结果:会在命令行所在的目录下多出一个文件info.txt;//info.txt文件中的内容如下/*module.js:340 throw err;^Error: Cannot find module 'E:\node\gys\javascript.js'at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3*///八:console.warn的用法和console.error()用法一样//九:console.time()和console.timeEnd()输出中间代码的执行时间(注意:time和timeEnd的参数必须完全一致) console.time("for循环的时间:") var a=0;for(var i=0;i a++;}console.timeEnd("for循环的时间:")/** 10.console.trace()方法将当前位置处的栈信息作为标准错误信息进行输出.

*  */ var obj={name:"guoyansi",age:23,eat:function(){}}console.trace(obj);//输出结果:不知道你能不能看懂,反正我是看不懂的.

1 //十:console.assert()对表达式结果进行评估,如果该表达式的执行结果为false,则输出一个消息字符串并抛出AssertionError异常2 console.assert("g"==="s","g不等于s");Node.js中文手册Node.js 中文手册下载下载是不是很简单呢,额。。反正我是感觉看不懂,哈哈

相关文章