A one-file remote console.log using node.js
By Alex Kessinger on
Find me on: Google+, Twitter, and email
I am slightly ashamed to admit this, but just the other day I realized that node.js was more then just a webserver. For some reason I had got it into my head that node.js was just for webservers, or network like things.
But after I installed node.js, I realized that this was rockin javascript environment that works like python’s interactive command line.
The fact that it has http at it’s core though makes is super simple to write one-off network handlers, and this got my mind churning. I created a one-file remote console.log. I have found some prior art iphonedebug, and the one by Jow Hewitt, both were a little more complicated then running one file, and inserting one JS include, so I wrote my own. Here is how it works. First install node.js. I use homebrew.
Next checkout the github project.
git clone git://github.com/voidfiles/Node.js-Remote-Console.log.git remoteconsole;
cd remoteconsole;
node remote_console.js
Now you should have it running on http://127.0.0.1:8124/. Next you just insert this this script tag somewhere before you will want to use it
<script src="http://127.0.0.1:8124/debug.js" type="text/javascript"></script>
There you are, now you can call log() from anywhere in your code, and your arguments will be serialized into JSON, and sent to the remote console.
I stole this console.log from Paul Irish.
There is also a function called catchRemote, if you pass it a function, it will immediately execute that function, and catch the errors. Those errors will then be logged using log.
One note, this only works in browsers with native JSON. If your browser does not have native JSON, then you can include JSON2.