szydan
szydan

Reputation: 2596

nodejs console.log of object

I'm printing the error object in nodejs. The output of console.log(err) looks like:

{ [error: column "pkvalue" does not exist]
  name: 'error',
  length: 96,
  severity: 'ERROR'}

What is the information printed in square brackets and how to access it ?

Upvotes: 1

Views: 408

Answers (2)

vp_arth
vp_arth

Reputation: 14982

It just common Error part
Rest is additional defined fields:

$ node
> var e = new Error('Some error');
undefined
> e.field = 'value'
'value'
> console.log(e)
{ [Error: Some error] field: 'value' }

You can access to error message as message field:

> e.message
'Some error'

Upvotes: 1

Blaise
Blaise

Reputation: 13479

You could try to use util.inspect instead, it gives more verbose information and serialize objects to strings differently.

See https://nodejs.org/api/util.html#util_util_inspect_object_options

Upvotes: 0

Related Questions