How do you log content of a JSON object in Node.js? Ask Question

How do you log content of a JSON object in Node.js? Ask Question

Is it possible to print an objects contents e.g. methods and attributes in Node.js?

At the moment I'm trying to print the session object and get the following:

console.log("Session:" + session);
> Session:[object Object]

おそらく、PHP の print_r(array) や Java の .toString を使用するのと同様の方法でしょう。

ベストアンサー1

これを試してみてください:

console.log("Session: %j", session);

オブジェクトを JSON に変換できる場合は、それが機能します。

おすすめ記事