Printing to output Terminal
I’m currently trying to modify some modules and can’t figure out how to consistently output to the terminal for my own debugging process.
I use console.log(“xxxxx”) in a “node_helper.js” file and it seems to print just fine. But when I go to the actual “module.js” file, nothing i put in the console.log(“xxxx”) goes to the terminal. Help please!
It you call console.log() in the module.js, the output will go to your browsers web-console. Have in mind, that the module.js is executed by your browser (client-like) when you open magicmirror there while the node_helper.js is executed when you start the magicmirror-server (server-like) and runs all the time. So to bring the output of your module.js to your terminal, you would have to send this data with a socketNotification to your node_helper.js and print it there.
@LukeCodewalker Thanks for helping me understand that. After poking around a bit, I found this topic: https://forum.magicmirror.builders/topic/86/how-to-troubleshoot
Am I correct in understanding that if I call a “console.log()” in a module.js, I should be able to see the output in the pm2 logs? Because right now I am having trouble with that.
I have no problem running the mirror with pm2, and I can pull the logs no problem. But all the logs show are just the typical startup stuff. None of the random text outputs I have tried to put in with “console.log()” command. Please help!
I don’t know your testing setup, but you usually can open up your browser (on your computer, not the pi) go to
http://YOUR-PI-IP:8080and then open up your broswer’s console. In chrome (using windows) you press
ctrl+shift+i, if you’re using firefox it’s
ctrl+shift+k. That’s where all of your
console.logmessages (from the module.js) will appear. But @LukeCodewalker is correct, you won’t see node_helper.js messages there. You can view those from the console
tail -f .pm2/logs/mm-out-0.log&
tail -f .pm2/logs/mm-error-0.log. That is, if you’re using the pm2 autostart from here.
@mochman Now I get it! Thanks so much for laying out the basics for me! First time dealing in server/client stuff and I’m starting to make sense of it in my head.