Simple Nodejs watcher

I built a simple Nodejs watcher that is syncing changes made in your CSV file to MongoDB. So let’s say you have some service that exports periodically CSV file which you want later to sync with the database, in this case, MongoDB.

My approach was to have a script that will run (continuously) and whenever you made some changes in the CSV file it should update the database.
For my scenario, I have one collection in the database called properties.

const dataCsv = './sample_data.csv';
const mongodb = require("mongodb").MongoClient;
const csvtojson = require("csvtojson");
const fs = require('fs');
let url = "mongodb://yoururl";

As you can see I am using MongoClient, CSVTOJSON and FS.
Below is the rest of the code, as you can see it is very simple, connect to MongoDB and watch changes when they appear. Also, I put console.log to see what is happening.

fs.watchFile(dataCsv, (curr, prev) => {

        .then(csvData => {
                { useNewUrlParser: true, useUnifiedTopology: true },
                (error, client) => {
                    if (error) return console.log(error);
                    let dbo = client.db('databsename');
                        .deleteMany({},(err, data) => {
                            if (err) return console.log('err', err);
                                .insertMany(csvData, (err1, res) => {
                                    if (err1) return console.log(err1);

                                    console.log(`Inserted: ${res.insertedCount} rows`);

    console.log(`${dataCsv} file Changed`);

You can also read this

Simple Todo app with Node.js and Express

In this quick tutorial we will be creating a Todo...

app.listen(8080, function () {
  console.log('Running on port 8080!')

Responsive CSS counter without Javascript

CSS counters let you adjust the appearance of content based on...

@media (max-width: 319px) {
    .small-card__item:nth-child(1)~.small-card__item {
        counter-increment: item-count;