title: How to pipe output of a node CLI program to shell?
body: <p>I basically want to do something like this:</p>
  
  <pre><code>$ my-node-cli &lt;some-param&gt; | less
  </code></pre>
  
  <p>Note that <code>less</code> is just an example. I need it to work with any other *nix command.  </p>
  
  <p>More about the use case:<br>
  I wrote a node CLI package that searches some online resource and outputs results to the shell. Since the result set can be huge, client wants to do additional operations on it, e.g <code>grep</code>, <code>head</code>, <code>tail</code>, <code>tee</code>, ... anything really.</p>
  
  <p>I searched far and wide and I only managed to find the way to pipe <em>into</em> node program, not <em>out of</em>. My current idea is to capture the right side of pipe when my program is called, then, after I obtain results, execute my results concatenated with pipe (and that part I remembered when I was called) using <code>child_process.exec</code>. Not sure whether that could work though?  </p>
  
  <p>Note that each time my program is called it's a new process, i.e. the program doesn't have it's own prompt.</p>
  
  <p>Thanks</p>