Meteor debugs and shows warnings, logs and messages

I am new to Meteor and I am still trying to figure out how some things work. To better understand the language and workflow, using alerts and printing messages to the console is a great idea. But I'm stuck on a few things

I wonder if the default easy way is to print messages to the console. For example, when I submit the form, I cannot get it to work, and I cannot see the message I was typing in the browser console.

How can i do this? Perhaps printing messages to the system console where the server is running? Any further advice on using the console, showing messages and warnings?

+3


source to share


1 answer


You mostly use console.log()

to print logs to console in javascript, which basically means this function.

If you don't see any results on the chrome console waiting for it, it could be for several reasons:

  • Yours is console.log()

    not being reached when you execute your code. Make sure it is not in the wrong conditional expression.

Example:

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

      

  • Yours console.log()

    runs on the server side, so its output will be printed on your server logs, usually near the terminal window that the meteorite is running on


Example:

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

      

  • If you notice the error message undefined

    , the variable you are trying to print has not yet been defined. Make sure your variable is set before printing.

Example:

> var real_friend = "Bobby";
> console.log(real_friend);
"Bobby"
> console.log(imaginary_friend);
Error: 'imaginary_friend' is undefined.

      

+1


source







All Articles