zoukankan      html  css  js  c++  java
  • nodejs学习笔记Node.js 调试命令

    3.4  调试        47 

    下面是一个简单的例子: 

    $ node debug debug.js 

    < debugger listening on port 5858 connecting... ok 

    break in /home/byvoid/debug.js:11 var a = 1;

    2 var b = 'world'; 

    3 var c = function (x) { debug> n 

    break in /home/byvoid/debug.js:21 var a = 1;

    2 var b = 'world'; 

    3 var c = function (x) { 

    4    console.log('hello ' + x + a); debug> sb('debug.js', 4) 

    1  var a = 1; 

    2  var b = 'world'; 

    3  var c = function (x) { 

    *  4   console.log('hello ' + x + a); 

    5  }; 

    6  c(b); 

    7  }); 

    debug> c 

    break in /home/byvoid/debug.js:42 var b = 'world';

    3 var c = function (x) { 

    * 4   console.log('hello ' + x + a); 

    5  }; 

    6  c(b); debug> repl 

    Press Ctrl + C to leave debug repl 

    >  x 

    'world' > a + 1 2 

    debug> c 

    < hello world1 program terminated

     

     

    3.4.2  远程调试 

    V8 提供的调试功能是基于 TCP 协议的,因此 Node.js 可以轻松地实现远程调试。在命 令行下使用以下两个语句之一可以打开调试服务器: 

    node

    --debug[=port] script.js

    10

    node

    --debug-brk[=port] script.js

     

    48        第 3 章    Node.js 快速入门 

    node --debug 命令选项可以启动调试服务器,默认情况下调试端口是 5858,也可以 使用 --debug=1234 指定调试端口为 1234。使用 --debug 选项运行脚本时,脚本会正常 执行,但不会暂停,在执行过程中调试客户端可以连接到调试服务器。如果要求脚本暂停执 行等待客户端连接,则应该使用 --debug-brk 选项。这时调试服务器在启动后会立刻暂停 执行脚本,等待调试客户端连接。 

    当调试服务器启动以后,可以用命令行调试工具作为调试客户端连接,例如: 

    //在一个终端中 

    $ node --debug-brk debug.js 

    debugger listening on port 5858 

    //在另一个终端中 

    $ node debug 127.0.0.1:5858 connecting... okdebug> n 

    break in /home/byvoid/debug.js:21 var a = 1;2 var b = 'world'; 

    3 var c = function (x) { 

    4 console.log('hello ' + x + a); debug> 

    事实上,当使用 node debug debug.js 命令调试时,只不过是用 Node.js 命令行工 具将以上两步工作自动完成而已。

  • 相关阅读:
    用指针方法排序数组
    struct和typedef struct
    结构体类型定义的一般式
    HDOJ1020 Encoding
    malloc函数详解
    新手入门 acm 输入输出练习
    【算法入门】广度/宽度优先搜索(BFS)
    C++栈和队列
    hdu畅通工程
    codevs 2639 约会计划
  • 原文地址:https://www.cnblogs.com/zzcit/p/6404999.html
Copyright © 2011-2022 走看看