从Node.js输出到Chrome控制台 [英] Output to Chrome console from Node.js

查看:306
本文介绍了从Node.js输出到Chrome控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来直接输出节点变量到google chrome浏览器控制台。同样的方式, console.log()在客户端工作。像这是php 。这将大大加快开发。

解决方案

NodeMonkey真的很棒。 (我同意honzzz)



1。这是非常,超级简单的使用:



所有你需要做的是将其包含在你的node.js文件npm install node-monkey):

  require('node-monkey' 127.0.0.1,port:50500}); 

(如果不指定主机和端口, :http:// 0.0.0.0:50500)



然后转到http:// 127.0.0.1:50500,打开浏览器控制台在我的情况下)。
所有控制台输出都将记录在那里。



2。随您的应用程式自动启动



您不必打开另一个命令提示符即可启动它



3。您不必每次重新启动应用程式时都必须重新整理浏览器



一旦您开启应用程式,就可以随时打开该控制台,



(唯一的缺点是,如果停止你的应用程序很长一段时间)



编辑: p>

我已经切换到 node-inspector ,我认为这是一个更好的选择。
即使控制台消息没有输出到Chrome控制台,它也提供了更好的代码检查使用断点和手表。



这也很容易使用:



从NPM全局安装后,( npm install -g node-inspector



1。在命令提示符下使用以下命令启动调试器:

  node-inspector& 

2。在另一个命令提示符下使用以下命令启动节点应用程序:

  node --debug yourNodeProgram.js 

3。前往 http://127.0.0.1:8080/debug?port=5858 浏览器和设置断点,手表等就像你会做一个前端应用程序。



很好的部分是,每当你重新启动节点应用程序,你可以离开节点检查器。每次重新启动后,您只需刷新浏览器中的节点检查器页面。


I'm looking for a way to output Node variables directly into the google chrome browser console. The same way a console.log() works on the client side. Something like this for php. This would greatly speed up development.

解决方案

NodeMonkey is really awesome. (I agree with honzzz)

1. It's VERY, SUPER simple to use:

All you need to do is include this in your node.js file (after installing it with "npm install node-monkey"):

require('node-monkey').start({host: "127.0.0.1", port:"50500"});

(If you don't specify host and port, default is host/port pair is : http:// 0.0.0.0:50500)

Then go to http:// 127.0.0.1:50500, and open the browser console (Chrome in my case). All console output will be logged there.

2. Starts automatically with your application

You don't have to open another command prompt to start it up

3. You don't have to refresh the browser every time you restart your application

Once you fire it up, you can leave that console open all the time, and do whatever with your node program, and it will re-connect every time you restart it.

(only drawback is that if stop your application for a long time, your console will be polluted with error messages, which you can clear out, of course)

EDIT:

I have switched to node-inspector and I think it's a better choice. Even though the console messages are not output-ed to the Chrome console, it provides a better code inspection using break-points and watches.

It's also easy to use:

After installing it from NPM globally, (npm install -g node-inspector)

1. start debugger in a command prompt using the following:

node-inspector &

2. start your node application in another command prompt with the following:

node --debug yourNodeProgram.js

3. go to http://127.0.0.1:8080/debug?port=5858 in the browser and setup breakpoints, watches, etc just like you would do a front-end application.

The good part is that everytime you restart your node application, you can leave the node-inspector on. After every restart you can just refresh the node-inspector page in the browser.

这篇关于从Node.js输出到Chrome控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆