简体   繁体   English

如何在“Mac 终端”中使用“console.log”和 NodeJS 中的命令行“Local heroku”显示多行?

[英]How display multiple lines in the "Mac Terminal" using "console.log" with the command line "Local heroku" in NodeJS?

To launch my application,要启动我的应用程序,

when I use the command line : "node index.js" => my Mac Terminal displays all lines from an object.当我使用命令行时:“node index.js” => 我的 Mac 终端显示来自对象的所有行。

When I use the command line : "heroku local" => my Mac Terminal displays just only one line from an object.当我使用命令行时:“heroku local”=> 我的 Mac 终端仅显示来自对象的一行。

How can I display several lines on my Mac Terminal when I use "heroku local" ?使用“heroku local”时,如何在 Mac 终端上显示多行?

Thank you谢谢

So, this is only a guess here, but there may be a difference between versions of Node which is causing this behavioural change.所以,这只是一个猜测,但 Node 版本之间可能存在差异,这可能会导致这种行为变化。 Nonetheless, you can do a pretty-print in node using JSON.stringify:尽管如此,您可以使用 JSON.stringify 在节点中进行漂亮的打印:

var a = {foo: "baz", bar:{a: "b"}}
console.log(JSON.stringify(a, null, 4))

With any luck that will make them look the same.运气好的话会让他们看起来一样。 This is because JSON.stringify allows for a space formatting value as it's third parameter .这是因为 JSON.stringify 允许将空格格式化值作为第三个参数

Also, for better object inspection util.inspect allows better rending of information about objects, nested to a arbitrary degree (and including better error meta info which seems to be lost in a lot of stringification.此外,为了更好地检查对象, util.inspect允许更好地呈现关于对象的信息,嵌套到任意程度(并包括更好的错误元信息,这似乎在很多字符串化中丢失了。

var util = require('util');
var a = {foo: "baz", bar:{a: "b"}}
console.log(util.inspect(a));

However, I think util varies between nodeJS implementations, so you may see some variation.但是,我认为 util 因 nodeJS 实现而异,因此您可能会看到一些变化。 See here for the Node v5 implementation (latest at time of writing) 请参阅此处了解 Node v5 实现(撰写本文时的最新版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM