title: Setting Up Node.js so It Doesn't Crash Upon Encountering Error
body: <p>I am currently creating an API for a web scraping application to feed data from the web scraper into MongoDB. I have listed my code below that converts a .csv file to .json and then inserts it into MongoDB. The issue is, I have an index set up so that no two database entries are identical.</p>
  <p>Whenever this occurs, it throws an error (as it should), but it stops the running of the server which is not good. Would I need to use a try/catch statement for this? How would I format this for a try/catch statement? I just need it to continue running even if the database entry throws an error. Thank you for the assistance!</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>csvtojson()
  .fromFile("sample.csv")
  .then(csvData =&gt; {
    mongodb.connect(
      url,
      { useNewUrlParser: true, useUnifiedTopology: true },
      (err, client) =&gt; {
        if (err) throw err;
        client
          .db("databaseName")
          .collection("collectionName")
          .insertMany(csvData, options);
      }
    );
  });</code></pre>
  </div>
  </div>
  </p>