Output to Chrome console from Node.js

Viewed 30174

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.

7 Answers

NOTE: Since the old answer (written in september 2014) refers to an older version of node-inspector, my instructions are not relevant anymore in 2017. Also, the documentation has gotten a lot better, so I have updated my original answer:

node-inspector is what you need. It opens up an instance of Chrome with its developer tools for debugging.

It's also easy to use:

1. Install

$ npm install -g node-inspector

2. Start

$ node-debug app.js

Source: https://github.com/node-inspector/node-inspector

I know it's an old question but came on top of my Google search so maybe somebody will find my answer useful.

So you can use node --inspect-brk index.js

Now, all you have to do is basically just type chrome://inspect in your Chrome address bar and click Open dedicated DevTools for Node

In DevTools, now connected to Node, you’ll have all the Chrome DevTools features you’re used to:

  • Complete breakpoint debugging, stepping w/ blackboxing

  • Source maps for transpiled code

  • LiveEdit: JavaScript hot-swap evaluation w/ V8

  • Console evaluation with ES6 feature/object support and custom object formatting

  • Sampling JavaScript profiler w/ flamechart

  • Heap snapshot inspection, heap allocation timeline, allocation profiling

  • Asynchronous stacks for native promises

Hope that helped.

You can use bonsole, a simple way to log something in browser. Even in Linux, you can go to the LAN's ip to check it.

The most simple way with least dependencies is using a WebSocket connection to send the messages to the browser. Any WebSocket example you can find on the internet will suffice to accomplish this. Everything else requires to be heavily integrated into the host system and wouldn't work if you want to actually run this on a remote server. You can also send commands to the server directly from the browser console this way.

Links:
https://www.npmjs.com/package/websocket
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Related