title: How to pipe a stream to a file descriptor in node?
body: <p>I'm writing a cli in node, I want to open the users $EDITOR to edit data that is read from a stream (an http response IncomingMessage).</p>
  
  <p>How can I send the data to a file descriptor?</p>
  
  <p>In bash I could write this:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$EDITOR &lt;(curl $url)
  </code></pre>
  
  <p>or </p>
  
  <pre class="lang-sh prettyprint-override"><code>$DIFF &lt;(curl $url_1) &lt;(curl $url_2)
  </code></pre>
  
  <p><code>&lt;(curl $url)</code> expands to something like <code>/proc/self/fd/11</code></p>
  
  <pre class="lang-sh prettyprint-override"><code>echo &lt;(curl $url)
  /proc/self/fd/11
  </code></pre>
  
  <p>But how would I write it in javascript?</p>
  
  <pre><code>import cp from 'child_process'
  const fisrt = request(...);
  const second = require(...);
  const first_fd = ???;
  const second_fd = ???;
  
  const proc = cp.spawn(process.env.DIFF, [first_fd, second_fd] { stdio: 'inherit' });
  </code></pre>
  
  <p>Okay, if <code>stream</code> is backed by a socket or fd you can pass it to <code>options.stdio</code>, but what if it isn't, what if it's a transform stream?</p>
  
  <blockquote>
    <p><a href="https://nodejs.org/api/child_process.html#child_process_options_stdio" rel="nofollow noreferrer">options.stdio</a>
     object - Share a readable or writable stream that refers to a tty, file, socket, or a pipe with the child process. The stream's underlying file descriptor is duplicated in the child process to the fd that corresponds to the index in the stdio array. The stream must have an underlying descriptor (file streams do not until the 'open' event has occurred).</p>
  </blockquote>
  
  <p>Yes I could create a temp file but can I do it without one?</p>