Javascript Meteor调试和显示警报、日志和消息

Javascript Meteor调试和显示警报、日志和消息,javascript,node.js,meteor,Javascript,Node.js,Meteor,我是流星的新手,我仍在努力了解一些事情是如何运作的。为了更好地理解该语言和工作流,使用警报并将消息打印到控制台是一个好主意。但我有几件事要做 我想知道这是否是一种将消息打印到控制台的简单默认方式。例如,当我提交表单时,我无法发出工作警报,也看不到我打印的浏览器控制台消息 我怎么能做这种事?可能是将消息打印到服务器运行的系统控制台?关于如何使用控制台、显示消息和警报,还有什么建议吗?您基本上可以使用console.log()以javascript将日志打印到控制台,这就是此函数的基本含义 如果您在

我是流星的新手,我仍在努力了解一些事情是如何运作的。为了更好地理解该语言和工作流,使用警报并将消息打印到控制台是一个好主意。但我有几件事要做

我想知道这是否是一种将消息打印到控制台的简单默认方式。例如,当我提交表单时,我无法发出工作警报,也看不到我打印的浏览器控制台消息


我怎么能做这种事?可能是将消息打印到服务器运行的系统控制台?关于如何使用控制台、显示消息和警报,还有什么建议吗?

您基本上可以使用
console.log()
以javascript将日志打印到控制台,这就是此函数的基本含义

如果您在chrome控制台中未看到任何预期结果,可能有以下几个原因:

  • 执行代码时未到达您的
    console.log()
    。确保它不在错误的条件范围内
例如:

if (false)
  console.log('print me!'); // this desperate log will never see the light of day
else
  console.log('No, print me!'); // this one always will
if (Meteor.isServer)
  console.log('I\'m on the server!'); // this log will print on the server console
if (Meteor.isClient)
  console.log('I\'m on the client!'); // this log will print on the chrome console
console.log('I\'m omnipresent'); // this log will print on both
> var real_friend = "Bobby";
> console.log(real_friend);
"Bobby"
> console.log(imaginary_friend);
Error: 'imaginary_friend' is undefined.
  • 您的
    console.log()
    是在服务器端运行的,因此它的输出将打印在您的服务器日志上,通常是运行meteor一侧的终端窗口
例如:

if (false)
  console.log('print me!'); // this desperate log will never see the light of day
else
  console.log('No, print me!'); // this one always will
if (Meteor.isServer)
  console.log('I\'m on the server!'); // this log will print on the server console
if (Meteor.isClient)
  console.log('I\'m on the client!'); // this log will print on the chrome console
console.log('I\'m omnipresent'); // this log will print on both
> var real_friend = "Bobby";
> console.log(real_friend);
"Bobby"
> console.log(imaginary_friend);
Error: 'imaginary_friend' is undefined.
  • 如果弹出提示
    未定义的
    时出错,则表示您试图打印的变量尚未定义。在打印变量之前,请确保已设置该变量
例如:

if (false)
  console.log('print me!'); // this desperate log will never see the light of day
else
  console.log('No, print me!'); // this one always will
if (Meteor.isServer)
  console.log('I\'m on the server!'); // this log will print on the server console
if (Meteor.isClient)
  console.log('I\'m on the client!'); // this log will print on the chrome console
console.log('I\'m omnipresent'); // this log will print on both
> var real_friend = "Bobby";
> console.log(real_friend);
"Bobby"
> console.log(imaginary_friend);
Error: 'imaginary_friend' is undefined.

如果您使用chrome进行表单提交,如果您希望控制台日志,您可以使用
preserve log checkbox
选项来保存日志。这真的很有帮助。但是你知道在系统控制台上显示日志的方法吗?不,我不知道其他方法。我也在寻找这个问题的好答案,我有一个问题。我将回调设置为
集合.insert
方法。如果我尝试
console.log('Test')
不打印任何内容。但是如果我
console.log(id)
带有返回的id,它会在控制台中打印id。如果我使用变量而不是字符串,它也会失败。看来我们不能依靠这种方法了?发生了什么事?