node-inspector-sans-ws
Version:
Web Inspector based nodeJS debugger
86 lines (58 loc) • 1.99 kB
Markdown
Node Inspector provides two ways of embedding in third-party
applications.
1. Start the Node Inspector in a new process using
[](http://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)
2. Add `message` handler to get notified about Node Inspector events, use
`msg.event` to check which event was emitted.
```js
var fork = require('child_process').fork;
var inspectorArgs = [];
var forkOptions = { silent: true };
var inspector = fork(
require.resolve('node-inspector/bin/inspector'),
inspectorArgs,
forkOptions
);
inspector.on('message', handleInspectorMessage);
function handleInspectorMessage(msg) {
switch(msg.event) {
case 'SERVER.LISTENING':
console.log('Vising %s to start debugging.', msg.address.url);
break;
case 'SERVER.ERROR':
console.log('Cannot start the server: %s.', msg.error.code);
break;
}
}
```
Emitted when the HTTP server was bound and is ready to accept connections.
Properties:
* `address` - Server address as returned by `DebugServer.address()` (see
below).
Emitted when there was an error while setting up the HTTP server.
Properties:
* `error` - The error.
To be done. [index.js](../index.js) should expose method for creating and starting
a DebugServer instance with a given config.
DebugServer is already exposing the following API:
Returns the result of `server.address()` plus the URL of the Node Inspector
page to open in browser.
Example:
```js
{
port: 8080,
address: '0.0.0.0',
url: 'http://localhost:8080/debug?port=5858'
}
```
Emitted when the HTTP server was bound and is ready to accept connections.
* Error Object
Emitted when there is an error in setting up the HTTP server.