Better Node.js Console Dumps with console-probe

By  on  

Writing JavaScript in the Node.js environment has always felt a bit more difficult; probably because browser developer tools have become incredibly powerful, interactive, and visually appealing.  Using console.log on the client side isn't the best of experiences and obviously isn't interactive.

Though not interactive, I've found that console-probe is an improvement over console.log, providing me highlighted property types, lengths, and a nice visual tree view.

const probe = require('console-probe')

const donut = {
  'id': '0001',
  'type': 'donut',
  'name': 'Cake',
  'description': 'A small fried cake of sweetened dough, typically in the shape of a ball or ring.',
  'ppu': 0.55,
  'common': true,
  'batters':
  {
    'batter':
    [
      { 'id': '1001', 'type': 'Regular' },
      { 'id': '1002', 'type': 'Chocolate' },
      { 'id': '1003', 'type': 'Blueberry' },
      { 'id': '1004', 'type': "Devil's Food" }
    ]
  },
  // .....


// Highlight nicely to console
const prober = probe.get()
prober(donut)

console-probe is one of those nice, luxury utilities that can make debugging in a static environment just a bit better!

Recent Features

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

  • By
    Responsive and Infinitely Scalable JS Animations

    Back in late 2012 it was not easy to find open source projects using requestAnimationFrame() - this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...

Incredible Demos

  • By
    MooTools ContextMenu Plugin

    ContextMenu is a highly customizable, compact context menu script written with CSS, XHTML, and the MooTools JavaScript framework. ContextMenu allows you to offer stylish, functional context menus on your website. The XHTML Menu Use a list of menu items with one link per item. The...

  • By
    Scrolling “Agree to Terms” Component with MooTools ScrollSpy

    Remember the good old days of Windows applications forcing you to scroll down to the bottom of the "terms and conditions" pane, theoretically in an effort ensure that you actually read them? You're saying "No David, don't do it." Too late -- I've done...

Discussion

  1. Console probe seems to be an interesting improvement and it is obvious it could make javascript programming simpler.

  2. Paolo

    Nice. For me though,

    console.dir({ process }, {colors: 1, depth: Infinity})

    (or any other depth that suits your use case) does the job for many use cases.

  3. Grant Carthew

    The console-probe package has been updated since this article was written. It now has complex type support.

    As Paolo has pointed out, console.dir is quite good however it is a little verbose when all you want to do is see the API that is exposed by an object. Also, console-probe includes function signatures.

  4. Thanks for clarification and one more guys, I have a request for you – Could you please help me change the directory of my Node.js script?

    #!/usr/bin/env node
    process.chdir('/Users')
    

    I know it can be done through process.chdir(directory) but I do not know how to do that.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!