How to get DOM from a file using jsdom?
<p>I'm using Node.js, its plugins Request and FS to save a Web page on my hard-disk. This is done by the following code :</p>

<pre><code>function loadURL(url, file_path, handler) {
    request.get(url).on('error', (error) =&gt; handler(error)).pipe(fs.createWriteStream(file_path, {'flags' : 'w'}))
}
</code></pre>

<p>I would want, now, to get the HTML DOM from this local file thanks to the Node.JS plugin JSDOM.</p>

<p>Thus :</p>

<ol>
<li>I must read this file thanks to the plugin FS ;</li>
<li>When all the file's HTML code is read, I must store the latter into a string ;</li>
<li>Finally, I must call : <code>jsdom.jsdom(the_string_containing_HTML_code)</code>.</li>
</ol>

<p>Step 3 is simple to do. The second too maybe.
However... how could I read asynchronously the local file using FS ? <code>read</code> function should not be used according to the documentation ; instead I should use <code>pipe</code>... but the latter just attaches a <code>WritableStream</code> to a <code>ReadableStream</code>... it does not satisfy what I'm wanting.</p>

<p>NB : I really want to use asynchronous methods.</p>