Saturday, 6 May 2017

Cannot convert object to primitive value when iterating through request.connection

I have the following script to iterate through the properties of the request.connection object:

p
 - for (var key in req.connection)
   | #{key} : #{req.connection[key]}
   br

On a Ubuntu server with Node.js v4.2.6 it prints out fine. On my Windows PC Node.js v6.9.2 it gives:

Cannot convert object to primitive value

Thinking that one of the properties of req.connection is not a string, I tried:

p
 - for (var key in req.connection)
   if (typeof(key) === "string")
     | string #{key} : #{req.connection[key]}
     br
   else
     | Not string: #{typeof key}
     br

But the same error still persist in v6.9.2 at the fourth line. I am puzzled. What could be causing the error?



via Old Geezer

No comments:

Post a Comment