Debug in Node.js

  • Using console object: console.log(‘xxx‘);
  • Using Node.js internal debugger (v8 engine): node debug xxx.js

refer to: https://nodejs.org/api/debugger.html#debugger_debugger

How to use node-inspector:

  1. In one terminal, run "node-inspector" to start the node inspector server.
  2. In another terminal, run
     node --debug your/node/program.js
  1. Or
    node --debug-brk your/short/node/script.js // pause your script on the first line

    to start your node process.

  2. Launch Chrome or Opera, open http://127.0.0.1:8080/debug?port=5858 to
    launch debugger UI. (Server code can be shown here)

    • You can set breakpoint to code (although you may cannot see the breakpoint first time, click "Refresh" button on browser, you can see program will stop at the breakpoint you set last time.)
时间: 2024-08-27 12:02:31

Debug in Node.js的相关文章

Node.js使用supervisor遭遇‘supervisor’不是内部或外部命令,如果解决?

如果你有 PHP 开发经验,会习惯在修改 PHP 脚本后直接刷新浏览器以观察结果,而你 在开发 Node.js 实现的 HTTP 应用时会发现,无论你修改了代码的哪一部份,都必须终止 Node.js 再重新运行才会奏效.这是因为 Node.js 只有在第一次引用到某部份时才会去解析脚 本文件,以后都会直接访问内存,避免重复载入,而 PHP 则总是重新读取并解析脚本(如 果没有专门的优化配置).Node.js的这种设计虽然有利于提高性能,却不利于开发调试,因 为我们在开发过程中总是希望修改后立即看

[Express + Webstrom] Debug Node.js RESTful application

Using WebStrom can easily debug the Node applcation. For example, we have an Node+Express application. server.js: /** * Created by Answer1215 on 12/9/2014. */ 'use strict'; var expres = require('express'); var app = expres(); app.get('/', function(re

node.js 远程调试debug产线环境代码

一.背景: 产线机器出bug,不能重启服务,需要保留现场,问题不好排查,远程debug服务器端代码才是正解. 二.实现步骤 1. 登录远程机器执行如下命令,nodePid为node服务的pid kill -usr1 nodePid #此命令不会重启服务 2. 本地执行,映射远程服务端口到本地端口9229,后续chrome调试使用 ssh -L 9220:localhost:9229 username@40.xxx.xx.xxx 3. 本地机器,chrome打开 chrome://inspect/

electron node.js 在 vscode 设置 调试 Debug

在当前工程下,添加一个 .vscode/launch.json 文件 { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.

使用NPM安装Node.js模块以及调试

npm npm 作为Node.js的包管理器,是经常用到的工具. 注意:全局安装一个框架,需要加参数-g npm install -g express 安装后 在项目中只需要导入包即可 var http = require('http'); 调试 调试Node的最简单的方式就是console.log(),但是有时候也需要单步调试 在需要调试的地方写入debugger node debug *.js node中的测试命令: next,n:单步执行 cont,c:继续执行,直到遇到下一个断点 ste

使用Chrome DevTools直接调试Node.js与JavaScript(并行)

Good News: 现在我们可以用浏览器调试node.js了!!! 前提 Node.js 6.3+, 这个可上Node.js官网自行下载: Chrome 55+. 如果您本地的chrome升级到最新版后还是<55, 可以从此处下载:Chrome Canary,亲测可行. 配置 就目前来说,在浏览器端并行调试JavaScript与Node.js还属于新特性,新体验.为了能够正常使用,你还需要做如下配置: 输入url:chrome://flags/#enable-devtools-experime

Node.js的集群功能以及在Express的配置

Node.js在v0.6.0版本下内置了集群功能,作为cluster模块,用于nodejs的多核处理,也比较容易通过脚本实现一个负载均衡的集群. 脚本参考了其他人的材料,建立一个server.js(因为虚拟机只有1核,为模拟多线程,所以采用numCPUs+4) var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.is

Node.js【4】简介、安装和配置、快速入门

笔记来自<Node.js开发指南>BYVoid编著 第1章 Node.js简介 Node.js是一个让JavaScript运行在服务端的开发平台,它让JavaScript成为脚本语言世界的一等公民,在服务端堪与PHP.Python.Perl.Ruby平起平坐. Node.js可以作为服务器向用户提供服务,与PHP.Python.RubyonRails相比,它跳过了Apache.Nginx等HTTP服务器,直接面向前端开发. Node.js还可以调用C/C++的代码,这样可以充分利用已有的诸多函

node.js 和 node-webkit C++扩展方法

构建node扩展的方法: 1,安装node.js 版本为0.10.24.msi 2,安装node-gyp, npm install -g node-gyp 3,构建 hello工程 cd 到 node-gyp-hello\src node-gyp configure node-gyp build 构建node-webkit扩展的方法: 1,安装node.js 版本为0.10.24.msi 2,安装nw-gyp, npm install -g  nw-gyp 3,构建 hello工程 cd 到 n