diff --git a/.npmignore b/.npmignore index f5078ac..cc94b97 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ * !src/** !binding.gyp +!index.js diff --git a/README.md b/README.md index 8865428..665aeb6 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,26 @@ Supports Node.js v4, v6 and v7 on Linux, MacOS, Windows and AIX. ```bash npm install nodereport +node -r nodereport app.js ``` +A NodeReport will be triggered automatically on unhandled exceptions and fatal +error events (for example out of memory errors), and can also be triggered +by sending a USR2 signal to a Node.js process (Linux/MacOS only). -This will allow a NodeReport to be triggered via an API -call from a JavaScript application. +A NodeReport can also be triggered via an API call from a JavaScript +application. ```js var nodereport = require('nodereport'); nodereport.triggerReport(); ``` +The API can be used without adding the automatic exception and fatal error +hooks and the signal handler, as follows: + +```js +var nodereport = require('nodereport/api'); +nodereport.triggerReport(); +``` Content of the NodeReport consists of a header section containing the event type, date, time, PID and Node version, sections containing JavaScript and @@ -50,19 +61,12 @@ can be specified as a parameter on the `triggerReport()` call. nodereport.triggerReport("myReportName"); ``` -A NodeReport can also be triggered automatically on unhandled exceptions, fatal -error events (for example out of memory errors), and signals (Linux/MacOS only). -Triggering on these events can be enabled using the following API call: - -```js -nodereport.setEvents("exception+fatalerror+signal+apicall"); -``` - ## Configuration Additional configuration is available using the following APIs: ```js +nodereport.setEvents("exception+fatalerror+signal+apicall"); nodereport.setSignal("SIGUSR2|SIGQUIT"); nodereport.setFileName("stdout|stderr|"); nodereport.setDirectory(""); diff --git a/binding.gyp b/binding.gyp index c665e5b..77272b1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "nodereport", + "target_name": "api", "sources": [ "src/node_report.cc", "src/module.cc" ], "include_dirs": [ ' { + tap.plan(3); + tap.equal(code, 0, 'Process exited cleanly'); + const reports = common.findReports(child.pid); + tap.equal(reports.length, 1, 'Found reports ' + reports); + const report = reports[0]; + common.validate(tap, report, {pid: child.pid}); + }); +} diff --git a/test/test-exception.js b/test/test-exception.js index 6e0e2f2..04f16a9 100644 --- a/test/test-exception.js +++ b/test/test-exception.js @@ -2,7 +2,7 @@ // Testcase to produce NodeReport on uncaught exception if (process.argv[2] === 'child') { - require('../').setEvents('exception'); + require('../'); function myException(request, response) { const m = '*** exception.js: testcase exception thrown from myException()'; diff --git a/test/test-fatal-error.js b/test/test-fatal-error.js index 038aa83..563a578 100644 --- a/test/test-fatal-error.js +++ b/test/test-fatal-error.js @@ -2,7 +2,7 @@ // Testcase to produce NodeReport on fatal error (javascript heap OOM) if (process.argv[2] === 'child') { - require('../').setEvents('fatalerror'); + require('../'); const list = []; while (true) { diff --git a/test/test-signal.js b/test/test-signal.js index c1fb7fa..d1a0761 100644 --- a/test/test-signal.js +++ b/test/test-signal.js @@ -3,7 +3,7 @@ // Testcase to produce NodeReport on signal interrupting a js busy-loop, // showing it is interruptible. if (process.argv[2] === 'child') { - require('../').setEvents('signal'); + require('../'); // Exit on loss of parent process process.on('disconnect', () => process.exit(2));