package
Minimal library for parsing and printing node stacktrace
npm install parsetraceGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.

Minimal library for parsing and printing node stacktrace. Mostly for use in express-error-with-sources.
npm install --save parsetrace
var parsetrace = require('parsetrace');
try {
throw new Error('My cool error');
} catch (e) {
console.log(parsetrace(e, { sources: true }).json());
}Parses stack trace from Error, string or object, that have .stack and .message property.
If callback is passed - all source code fetching will be async and error will be passed to it (even if strict is true).
parsetrace(err, function(error, trace) {
console.log(trace.toString());
});Options:
sources - fetch source code from files, that are mentioned in stacktrace. If file can not be found or readed - sources will be fetched silently (unless you enabled strict option) (default: false)strict - throws errors, while parsing stacktrace and fetching source code (default: false)contextSize - number of lines before and after the error line (default: 3)Returns Object with methods described below:
{
"error": "My cool error",
"frames": [
{
"line": 4,
"column": 11,
"function": "Object.<anonymous>",
"file": "/full/path/to/file.js",
"source": {
"2": { "code": "" },
"3": { "code": "try {" },
"4": { "code": " throw new Error('My cool error');" },
"5": { "code": "} catch (e) {" },
"6": { "code":
Returns stacktrace as Json string
Format of object you can see in json() section.
Returns stacktrace as Object
Options:
excludeSources - if stacktrace was parsed with sources, this will exclude them from output (default: false)Returns stacktrace as NodeJS formatted stacktracke string.