如何调试NodeJS
来源:互联网 发布:edu.cn域名查询 编辑:程序博客网 时间:2024/05/22 15:36
查看全文:http://ramonblog.cloudfoundry.com/blog/5002d26f4e1ef7b729000002
nodejs系列提纲
我终于要不能忍受CSDN这个垃圾网站的blog了,于是乎我决定借着学习nodejs的机会自己搭建一个blog,并且将其部署到cloudfoundry上。于是乎我将陆续完成下面的系列文章。所以文章里面的代码都是这个blog的实现。
- Why NodeJS
- nodejs的架构
- nodejs的hello world
- nodejs类库
- nodejs的plugin,如何实现一个plugin
- nodejs的web framework Expression
- nodejs与mongoDB
- nodejs与cloudfoundry
- nodejs如何调试(Node Inspector)
nodejs系列提纲
我终于要不能忍受CSDN这个垃圾网站的blog了,于是乎我决定借着学习nodejs的机会自己搭建一个blog,并且将其部署到cloudfoundry上。于是乎我将陆续完成下面的系列文章。所以文章里面的代码都是这个blog的实现。
- Why NodeJS
- nodejs的架构
- nodejs的hello world
- nodejs类库
- nodejs的plugin,如何实现一个plugin
- nodejs的web framework Expression
- nodejs与mongoDB
- nodejs与cloudfoundry
- nodejs如何调试(Node Inspector)
debug nodejs
Sure it's important to debug for any programming language, and it should be learnt at first time to use a new language. I forgot why I put this debug blog at the end of the serials blogs. No matter what's the reason, now we need to introduce how to debug nodejs. This article has two parts, one is the native debugger for nodejs, and another one is Node Inspector. In fact there is the third way to debug nodejs, based on Eclipse, which is not introduced here, but you can find more introduction from here: Using Eclipse as Node Applications Debugger.
NodeJS Built-in debugger
Prepare to debug Have below simple code as our sample, name it as 'debug.js'.
var count = 10;var sum = 0;debugger;for (var i = 1; i < count; i++) { sum += i;}console.log(sum);
Note we have
debugger;
at line 3, which means we put a breakpoint here. Actually it's the same with the normal Javascript running in browser Chrome, in which put adebugger;
statement. The difference it we add this statement into js code running in browser to force the execution to pause at load time. But in to debug nodejs, it's not necessary, because in debug mode the execution is always paused at first line.。。。。。。
Node Inspector
Finally we finish the basic commands of built-in debugger. Now we introduce a debug tool with UI, Chrome. You know nodejs is built on V8 js engine, which is the engine for Chrome browser, therefore it's a good idea to use Chrome as debug tool.
Setup debug
To use node-inspector we need change our sample code as below, which is from node-inspector test code, name it as 'debug.js' too.
var http = require('http');var x = 0;http.createServer(function (req, res) { x += 1; res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World ' + x);}).listen(8124);console.log('Server running at http://127.0.0.1:8124/');
Node Inspector only supports nodejs HttpServer, therefore we cannot debug previous sample code in before section, If we want to debug that code, we need wrap it into a http server like above sample code.
。。。。。。
查看全文:http://ramonblog.cloudfoundry.com/blog/5002d26f4e1ef7b729000002
- 如何调试NodeJS
- nodejs调试
- nodejs调试
- nodejs 调试
- Nodejs 调试
- nodejs 调试
- nodejs 调试
- Nodejs 调试
- nodejs开发中如何调试基于多进程的程序
- 如何使用DevTools调试Nodejs运行的Javascript
- 用Chrome调试NodeJS
- 调试nodejs服务端
- chrome 调试 nodejs
- nodejs 调试技巧
- nodejs 热调试
- nodejs使用supervisor 调试
- nodejs 调试总结
- 安装supervisor调试nodejs
- JSP web.xml 配置详解
- android 有关Activity的Launch mode 以及Intent的setFlags
- 邻接表-动态和静态的学习
- Aria2 下载工具安装和使用(ubuntu,fredora)
- JAVA另一种做日期加减法的方法(更简单)
- 如何调试NodeJS
- vc隐藏执行程序,即不显示窗体执行
- hdu 1541
- SQL server语言基础(一)
- jquery基础一
- PHP学习之七:扩展函数库-文件系统、进程与网络
- 我不知道的java_volatile + transient
- Timer定时器
- 林心如的落花