-
Notifications
You must be signed in to change notification settings - Fork 715
/
inspector.js
executable file
·70 lines (56 loc) · 1.42 KB
/
inspector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
var DebugServer = require('../lib/debug-server').DebugServer,
fs = require('fs'),
path = require('path'),
Config = require('../lib/config'),
packageJson = require('../package.json');
var config = new Config(process.argv.slice(2));
if (config.help) {
config.showHelp();
process.exit();
}
if (config.version) {
config.showVersion();
process.exit();
}
process.on('SIGINT', function() {
process.exit();
});
console.log('Node Inspector v%s', packageJson.version);
var debugServer = new DebugServer();
debugServer.on('error', onError);
debugServer.on('listening', onListening);
debugServer.on('close', function () {
process.exit();
});
debugServer.start(config);
function onError(err) {
console.error(
'Cannot start the server at %s:%s. Error: %s.',
config.webHost,
config.webPort,
err.message || err
);
if (err.code === 'EADDRINUSE') {
console.error(
'There is another process already listening at this address.\n' +
'Run `node-inspector --web-port={port}` to use a different port.'
);
}
notifyParentProcess({
event: 'SERVER.ERROR',
error: err
});
}
function onListening() {
var address = this.address();
console.log('Visit %s to start debugging.', address.url);
notifyParentProcess({
event: 'SERVER.LISTENING',
address: address
});
}
function notifyParentProcess(msg) {
if (!process.send) return;
process.send(msg);
}