Node.js之Console用法小结
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /** * Created by city--online on 16/3/9. */ //console.time()和console.timeEnd()输出中间代码的执行时间(注意:time和timeEnd的参数必须完全一致) console.time( "hello" ); console.log( "hello world" ); //依次序输出所有字符串 console.log( "%s" , "Hello" , "World" ); //将对象转换为普通字符串后执行 console.log( "%s" , "cuiyanwei" ,{name: "小崔" }); //将字符串作为数值进行转换 console.log( "%d" , "25.6" ); console.log( "%d" , "cuiyanwei" ); // 输出% console.log( "%%" ); console.log( "%%" , "cyw" ); //console.warn的用法和console.error()用法一样 //console.error("this is error"); //console.trace()方法将当前位置处的栈信息作为标准错误信息进行输出. var obj={ name: "cuiyanwei" , age:24, eat: function (){ } } console.trace(obj); //查看对象里的内容并输出: console.dir(obj); //显示所有nodejs中的全局变量、函数、对象: console.log(global); //console.assert()对表达式结果进行评估,如果该表达式的执行结果为false,则输出一个消息字符串并抛出AssertionError异常 console.assert(2==1, "error 2==1" ); console.timeEnd( "hello" ); |
/usr/local/bin/node Console.js hello world Hello World cuiyanwei { name: '小崔' } 25.6 NaN %% % cyw Trace: { name: 'cuiyanwei', age: 24, eat: [Function] } at Object.<anonymous> (/Users/city--online/Desktop/Console/Console.js:37:9) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:134:18) at node.js:962:3 Trace: a at Object.<anonymous> (/Users/city--online/Desktop/Console/Console.js:39:9) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:134:18) at node.js:962:3 { name: 'cuiyanwei', age: 24, eat: [Function] } { DTRACE_NET_SERVER_CONNECTION: [Function], DTRACE_NET_STREAM_END: [Function], DTRACE_HTTP_SERVER_REQUEST: [Function], DTRACE_HTTP_SERVER_RESPONSE: [Function], DTRACE_HTTP_CLIENT_REQUEST: [Function], DTRACE_HTTP_CLIENT_RESPONSE: [Function], global: [Circular], process: process { title: '/usr/local/bin/node', version: 'v4.3.1', moduleLoadList: [ 'Binding contextify', 'Binding natives', 'NativeModule events', 'NativeModule buffer', 'Binding buffer', 'NativeModule internal/util', 'Binding util', 'NativeModule timers', 'Binding timer_wrap', 'NativeModule _linklist', 'NativeModule assert', 'NativeModule util', 'Binding uv', 'NativeModule path', 'NativeModule module', 'NativeModule internal/module', 'NativeModule vm', 'NativeModule fs', 'Binding fs', 'NativeModule constants', 'Binding constants', 'NativeModule stream', 'NativeModule _stream_readable', 'NativeModule _stream_writable', 'NativeModule _stream_duplex', 'NativeModule _stream_transform', 'NativeModule _stream_passthrough', 'Binding fs_event_wrap', 'NativeModule console', 'Binding tty_wrap', 'NativeModule net', 'Binding cares_wrap', 'Binding tcp_wrap', 'Binding pipe_wrap', 'Binding stream_wrap' ], versions: { http_parser: '2.5.2', node: '4.3.1', v8: '4.5.103.35', uv: '1.8.0', zlib: '1.2.8', ares: '1.10.1-DEV', icu: '56.1', modules: '46', openssl: '1.0.2f' }, arch: 'x64', platform: 'darwin', release: { name: 'node', lts: 'Argon', sourceUrl: 'https://nodejs.org/download/release/v4.3.1/node-v4.3.1.tar.gz', headersUrl: 'https://nodejs.org/download/release/v4.3.1/node-v4.3.1-headers.tar.gz' }, argv: [ '/usr/local/bin/node', '/Users/city--online/Desktop/Console/Console.js' ], execArgv: [], env: { SHELL: '/bin/bash', TMPDIR: '/var/folders/65/m0mbnd5515v0k2bnh6pzl75w0000gn/T/', __CF_USER_TEXT_ENCODING: '0x1F5:0x19:0x34', PATH: '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin', VERSIONER_PYTHON_VERSION: '2.7', XPC_FLAGS: '0x0', USER: 'city--online', HOME: '/Users/city--online', assert.js:89 LOGNAME: 'city--online', throw new assert.AssertionError({ XPC_SERVICE_NAME: '0', ^ Apple_PubSub_Socket_Render: '/private/tmp/com.apple.launchd.BNOh3IvDtv/Render', AssertionError: error 2==1 SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.30OLhAehof/Listeners', at Console.assert (console.js:87:23) VERSIONER_PYTHON_PREFER_32_BIT: 'no' }, at Object.<anonymous> (/Users/city--online/Desktop/Console/Console.js:46:9) pid: 5236, at Module._compile (module.js:409:26) features: at Object.Module._extensions..js (module.js:416:10) { debug: false, at Module.load (module.js:343:32) uv: true, at Function.Module._load (module.js:300:12) ipv6: true, at Function.Module.runMain (module.js:441:10) tls_npn: true, at startup (node.js:134:18) tls_sni: true, at node.js:962:3 tls_ocsp: true, tls: true }, _needImmediateCallback: false, execPath: '/usr/local/bin/node', debugPort: 5858, _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier], _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier], _getActiveRequests: [Function: _getActiveRequests], _getActiveHandles: [Function: _getActiveHandles], reallyExit: [Function: reallyExit], abort: [Function: abort], chdir: [Function: chdir], cwd: [Function: cwd], umask: [Function: umask], getuid: [Function: getuid], geteuid: [Function: geteuid], setuid: [Function: setuid], seteuid: [Function: seteuid], setgid: [Function: setgid], setegid: [Function: setegid], getgid: [Function: getgid], getegid: [Function: getegid], getgroups: [Function: getgroups], setgroups: [Function: setgroups], initgroups: [Function: initgroups], _kill: [Function: _kill], _debugProcess: [Function: _debugProcess], _debugPause: [Function: _debugPause], _debugEnd: [Function: _debugEnd], hrtime: [Function: hrtime], dlopen: [Function: dlopen], uptime: [Function: uptime], memoryUsage: [Function: memoryUsage], binding: [Function: binding], _linkedBinding: [Function: _linkedBinding], _setupDomainUse: [Function: _setupDomainUse], _events: { newListener: [Function], removeListener: [Function] }, _rawDebug: [Function], domain: null, _maxListeners: undefined, EventEmitter: { [Function: EventEmitter] EventEmitter: [Circular], usingDomains: false, defaultMaxListeners: 10, init: [Function], listenerCount: [Function] }, _fatalException: [Function], _exiting: false, assert: [Function], config: { target_defaults: [Object], variables: [Object] }, nextTick: [Function: nextTick], _tickCallback: [Function: _tickCallback], _tickDomainCallback: [Function: _tickDomainCallback], stdout: [Getter], stderr: [Getter], stdin: [Getter], openStdin: [Function], exit: [Function], kill: [Function], _eventsCount: NaN, mainModule: Module { id: '.', exports: {}, parent: null, filename: '/Users/city--online/Desktop/Console/Console.js', loaded: false, children: [], paths: [Object] } }, GLOBAL: [Circular], root: [Circular], Buffer: { [Function: Buffer] poolSize: 8192, isBuffer: [Function: isBuffer], compare: [Function: compare], isEncoding: [Function], concat: [Function], byteLength: [Function: byteLength] }, clearImmediate: [Function], clearInterval: [Function], clearTimeout: [Function], setImmediate: [Function], setInterval: [Function], setTimeout: [Function], console: [Getter] } Process finished with exit code 1
---------------我是有底线的--------------------
作者:社会主义接班人
出处:http://www.cnblogs.com/5ishare/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果文中有什么错误,欢迎指出。以免更多的人被误导。
作者:社会主义接班人
出处:http://www.cnblogs.com/5ishare/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果文中有什么错误,欢迎指出。以免更多的人被误导。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?