Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  182] [ 7]  / answers: 1 / hits: 18478  / 10 Years ago, mon, january 26, 2015, 12:00:00

I'm trying to see what the object contains



With console.log(obj) the console cuts off from the lines and I can't see the entire structure.



Then I tried writing it to a file



fs.writeFile('test', JSON.stringify(obj));


But I get some error about circular references.



Is there any other way to view the object lol? The object is a connection from the nodejs websocket module. The docs are very poor and I can't seem to find the property that holds the IP address :(


More From » node.js

 Answers
11

fs.writeFile('test', JSON.stringify(obj));


But I get some error about circular references.




That's what happens with JSON. JSON also ignores functions, regexes, dates, etc.



You can use util.inspect, which is what Node's console.log() uses internally to get the entire object, which can then be written to a file:



var util = require('util');
fs.writeFileSync('test.txt', util.inspect(obj));


And if you want infinite depth, and hidden properties:



util.inspect(obj, { showHidden: true, depth: null })

[#68083] Friday, January 23, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
3 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;