流星: 在服务器端进行调试

有人知道调试服务器端代码的好方法吗? 我尝试启用 Node.js debug,然后使用 node-spector,但它没有显示我的任何代码。

I end up using console.log but this is very inefficient.

更新: 我发现以下过程在我的 Linux 机器上运行正常:

  1. 当您运行陨石时,它将产生两个进程

    Process1:/usr/lib/meteor/bin/node/usr/lib/meteor/app/meteor/mete.js

    Process2:/usr/lib/meteor/bin/node/home/paul/code/bbtest _ code/bbtest02/. meteor/local/build/main.js —— keepalive

  2. 你需要在进程2上发送 kill-s USR1

  3. 运行 node- 检查器,您可以看到您的服务器代码

在第一次尝试时,我将/usr/lib/meteor/bin/meteor 中流星启动脚本的最后一行修改为

exec "$DEV_BUNDLE/bin/node" $NODE_DEBUG "$METEOR" "$@"

并在命令提示符下运行 NODE_DEBUG=--debug meteor。这是 process1上唯一的 put —— debug 标志,所以我只能在 node-spector 上看到流星文件,而且找不到我的代码。

有人能在 Windows 和 Mac 机器上检查一下吗?

33940 次浏览

我不知道为什么对你没用。
我可以通过在控制台(Mac)上执行以下步骤来使用它。

$ ps
$ kill -s USR1 *meteor_node_process_id*
$ node-inspector &

上述步骤在 https://github.com/dannycoates/node-inspector中已经提到,它是用来将节点检查器附加到正在运行的节点进程上的。

要在调试模式下启动 node.js,我是这样做的:

  1. Open/usr/lib/meteor/app/meteor/run.js
  2. 之前

    nodeOptions.push(path.join(options.bundlePath, 'main.js'));
    

    nodeOptions.push('--debug');
    

Here are additional practical steps for your to attach debugger eclipse:

  1. use '--debug-brk' instead of '--debug' here, because it's easier for me to attach node.js using eclipse as debugger.
  2. add 'debugger;' in the code where you want to debug.(I prefer this way personally)
  3. run meteor in console
  4. attach to node.js in eclipse(V8 tools, attach to localhost:5858)
  5. run, wait for debugger to be hit

when you start meteor in your meteor app folder, you'll see that "debugger listening on port 5858" in console.

流星应用程序是 Node.js 应用程序。当使用 meteor [run]命令运行流星应用程序时,您可以使用 配置 ABC1环境变量在调试模式下启动 node

ABc0环境变量的例子:

  • --debug
  • 指定端口
  • --debug-brk-第一个语句的中断
  • --debug-brk=5858-在第一个语句上指定端口和中断

如果你使用的是 export NODE_OPTIONS=--debug,那么从同一个 shell 运行的所有 meteor命令都会继承这个环境变量。或者,您可以使用 NODE_OPTIONS="--debug=47977" meteor仅为一次运行启用调试。

To debug, run node-inspector in a different shell, then go to http://localhost:8080/debug?port=<the port you specified in NODE_OPTIONS>, regardless of what node-inspector tells you to run.

在流星0.5.4中,这变得容易多了:

First run the following commands from the terminal:

npm install -g node-inspector
node-inspector &
export NODE_OPTIONS='--debug-brk'
meteor

And then open http://localhost:8080 in your browser to view the node-inspector console.

更新

自从流星1.0以来,你只需要输入

meteor debug

which is essentially a shortcut for the above commands, and then launch node inspector in your browser as mentioned.

更新

在流星1.0.2中添加了一个控制台或 shell。它可以在服务器上输出变量和运行命令:

meteor shell

我写了一个叫做 流星探测器的小流星软件包,它简化了节点检查器调试流星应用程序的使用。它在内部管理节点检查器的生命周期,因此,在一些文件发生更改后,用户不需要手动重新启动调试器。

有关更多细节和具体的使用说明,请参见 https://github.com/broth-eu/meteor-inspector

WebStorm 是对开源开发人员免费的强大 IDE,它使得调试服务器端变得更加容易。

我已经在 Windows 上测试过了,它的配置是无痛的——参见 我的回答

流星服务器控制台是解决我问题的一个检查器:

  1. 在项目文件夹中,添加智能包 server-eval:

    mrt add server-eval
    

    For Meteor 1.0:

    meteor add gandev:server-eval
    
  2. Restart meteor.

  3. Download crx Chrome extension file from here.
  4. Open extensions page in Chrome and drag crx file to extensions page.
  5. Restart Chrome.
  6. Check the web inspector out to eval server side code:

    enter image description here

In comparison with node-inspector, I have a clearer output.

如果您喜欢使用 NodeJS 的官方调试器,可以调用 NODE_OPTIONS='--debug' meteor,然后(在不同的 shell 上)调用 node debug localhost:5858

从 Meetor1.0.2开始,服务器端调试的最佳方式可能是直接使用新的内置 shell: 运行服务器运行 meteor shell。更多信息请点击: https://www.meteor.com/blog/2014/12/19/meteor-102-meteor-shell

关于流星1.0.3.1(更新到 Sergey. Simonchik 答案)

meteor run --debug-port=<port-number>启动服务器

点浏览器到 http://localhost:6222/debug?port=<port-number>

其中 <port-number>是您指定的端口。

在代码中添加一个 debugger;,在其中设置断点。

根据调用 debugger;的位置,它将在客户端或打开检查器的服务器浏览器窗口上中断。

我喜欢通过 GUI 设置断点。这样,我就不必记得从我的应用程序中删除任何调试代码。

This is how I managed to do it server side for my local meteor app:

meteor debug

这样启动你的应用程序。

打开 Chrome 到它给你的地址。你可能需要安装 https://github.com/node-inspector/node-inspector(它现在可能已经和流星绑定了?不确定)

你会看到一些奇怪的内部流星代码(不是你写的应用程序代码)。运行代码。这段代码只是启动服务器来侦听连接。

只有在按下播放键之后,您才会在调试器文件夹结构中看到一个名为 “应用程序”的新目录。里面有你的陨石项目文件。在这一行中设置一个断点。

打开应用程序的本地地址 。这将运行您的服务器端代码,您应该能够达到您的断点!

注意: 你必须重新打开检查器,并且每次重新启动应用程序时都要重新执行这个过程!

流星1.35.2跑

流星调试—— debug-port 5858 + n N 是一个非零数字,这将导致节点检查器使用8080 + n 作为 web 端口。