A Node.js module for inspecting, profiling and debugging Node.js applications through a web browser
A Node.js module for inspecting, debugging and interfacing with Node.js applications through a web browser
NodeMonkey runs a simple server and uses Socket.IO to create a websocket connection between the browser and server. Its primary feature captures anything that would normally be logged to the terminal and passes it to the browser for inspection.
The motivation for this project came from trying to debug a Node.js server I wrote that used websockets. I found it problematic trying to inspect objects with the terminal. I tried using the built-in debugging that works with the Chrome Developer Tools plugin for Eclipse. Unfortunately, I ran into a problem where setting breakpoints to inspect objects would cause the server to stop responding to heartbeats thus causing the client to disconnect. This would entirely mess up my debugging efforts. All I really needed to do was have a good way to inspect objects. I searched Google and found projects like node-inspector, which doesn't work with the latest versions of Node, and node-codein which has many bugs. And neither works with Firefox.
So NodeMonkey was born!
npm install node-monkey
- Log console output to the browser console
- Now provides a Bunyan stream (see below) interface!
- Register commands for your application that can be executed from the browser console
- Profile performance of sections of code
NodeMonkey is primarily designed for debugging and for now should only be used for such. I haven't implemented any sort of authorization
to prevent anyone from gaining access to the data that is dumped out. If you are concerned about other's potentially gaining access while
you are debugging, you should change the
0.0.0.0 to something more secure like
127.0.0.1. Definitely don't include it in
production code before authorization is in place.
To get a quick start see the limited examples below. For complete documentation see the following links:
Using NodeMonkey is extremely easy.
All you have to do is include the following line in your Node.js application.
Anything that is logged to the console after this will show up in the browser console once connected.
It captures all output to
var nomo = require'node-monkey'startoptions;
To connect your browser simply go to
http://0.0.0.0:50500 in your web browser.
If you change the default
port bindings be sure to adjust your URL accordingly.
As an alternative to viewing output through this page, you can also view output in the console of your own web application by including the following lines (adjust the host and port as necessary, this is based on the defaults):
NOTE: You do NOT have to refresh the page when you restart your Node.js application to continue to receive output. Socket.IO will automatically reconnect.
If you use the awesome Bunyan library for logging, you can now add node-monkey as a Bunyan log stream by simply passing
nomo.stream, like so:
var nomo = require'node-monkey'startbunyan = require'bunyan';var log = bunyancreateLoggername: 'app'streams:level: 'info'stream: nomostream;log.error'something happened';
Any messages Bunyan sends to the stream will be displayed in your browser console!
- host: The host network interface to bind to. Default is
0.0.0.0which means ALL interfaces.
- port: The port to listen on. Default is
- overrideConsole: Set this to
falseto prevent NodeMonkey from overriding the console functions when you start it. You can call
nomo.replaceConsole()any time to override the console functions and
nomo.revertConsole()to change it back. Default is
- suppressOutput: Use this to suppress terminal output when
console.log()is called, freeing the console from clutter and allowing you to only inspect objects through the browser. Default is
- saveOutput: If data is logged before you are able to connect your browser, you may still want to be able to view this data. Setting this option to
truecauses node-monkey to save the output and dump it out to the browser once you connect. Default is
false. NOTE This will not be effective in newer versions of Firefox that have a proper built-in dev console.
- clientMaxBuffer: The maximum number of messages to buffer while waiting for the console to open. Only has an effect if
saveOutputis enabled. Default is
- silent: If
truethen nothing will be logged to the console when started. Default is
- showCallerInfo: If
truethen call stack information will be collected and the file, line and column where the log call is made from will be displayed in the browser console. Note that when used as a Bunyan stream it will respect the
srcoption passed to Bunyan for messages written from Bunyan, even if this is set to
true. Default is
- convertStyles: Whether to convert style related terminal escape sequences to corresponding JS console styles. Default is