title: Executing mongoimport inside code with Javascript/Node.js
body: <p>Is there any library available in node.js/javascript that allows an individual to use <code>mongoimport</code> in code?</p>
  
  <p>To my understanding, mongoimport is kinda like an .exe, which you have to execute it first before being able to use its text input environment. </p>
  
  <p>Is it possible to execute mongoimport in my code and then parse whatever commands I need directly in my code?</p>
  
  <p>My current algorithm involves:</p>
  
  <pre><code>fs.appendFile('log.txt',JSON.stringify(obj, null, 2));
  </code></pre>
  
  <p>obj is an object which specifies what functions to parse into <code>JSON.stringify</code> with the <code>res</code> method of node.js (which requests HTTP responses)</p>
  
  <pre><code>var obj = {};
  obj.url = hostNames[i];
  obj.statusCode = res.statusCode;
  obj.headers = res.headers;
  </code></pre>
  
  <p>Then I use mongoimport to import this JSON doc into my MongoDB. </p>
  
  <p><code>mongoimport --host localhost -db scrapeapp -collection scrape --file log.txt --jsonArray</code></p>
  
  <p>This method is obviously inefficient. I would like to do all these steps in one going.</p>
  
  <p>Help appreciated</p>