stderr-error-parser

1.0.2 • Public • Published

stderr-error-parser

Node.js module to parse error stack from the stderr of a Node.js process

Installation

stderr-error-parser is available though npm

$ npm i stderr-err-parser

Using

// import stderr-error-parser
const parseError = require("stderr-error-parser");

const { exec } = require("child_process");
const path = require("path");

// filePath should be an absolute path
const filePath = path.resolve(
	__dirname,
	"executable-js-files",
	"throws-range-error.js"
);

exec(`node ${filePath}`, (error, stdout, stderr) => {
	if (stderr.trim() !== "") {
		const _parsed = parseError(filePath, stderr, stdout);
		console.dir(_parsed);
		/*
		_parsed =
		{
  			outputPart: 'Hello World!\n',
  			errorBody: {
				errorName: 'RangeError',
				errorMessage: 'This is a range error.',
				lineNumber: 2,
				columnNumber: 7,
				errorStack: 'RangeError: This is a range error.\n' +
				  '    at ....'
  			}
		}
		*/
	} else {
		console.log(stdout);
	}
});

Examples

To check some of the examples, clone the repository and install dependencies

$ git clone https://github.com/roshanadh/stderr-error-parser
$ cd stderr-error-parser
$ npm install

Then run the example you want to see

$ node examples/example-reference-error.js

Tests

To run the test suite, clone the repository and install dependencies, then run

$ npm test

Package Sidebar

Install

npm i stderr-error-parser

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

9.89 kB

Total Files

14

Last publish

Collaborators

  • roshanadh