text: const fs = require('fs');
  const mongoose = require('mongoose');
  const Tour = require('../../models/tourModel');
  const User = require('../../models/userModel');
  const Review = require('../../models/reviewModel');
  const dotenv = require('dotenv');
  dotenv.config({ path: './config.env' });
  
  const DB = process.env.DATABASE.replace(
    '<PASSWORD>',
    process.env.DATABASE_PASS
  );
  
  mongoose
    .connect(DB, {
      useNewUrlParser: true,
      useCreateIndex: true,
      useFindAndModify: false,
      useUnifiedTopology: true,
    })
    .then(() => {
      console.log('DB connection successful');
    });
  
  //read JSON File
  const reviews = JSON.parse(
    fs.readFileSync(`${__dirname}/reviews.json`, 'utf-8')
  );
  const users = JSON.parse(fs.readFileSync(`${__dirname}/users.json`, 'utf-8'));
  const tours = JSON.parse(fs.readFileSync(`${__dirname}/tours.json`, 'utf-8'));
  
  const importData = async () => {
    try {
      await Review.create(reviews);
      console.log('Reviews loaded to the database successfully ☺☺☺');
  
      await Tour.create(tours);
      console.log('Tours loaded to the database successfully ☺☺☺');
  
      //Don't forget to disable the pre-save hook/middleware for password hashing
      await User.create(users, { validateBeforeSave: false });
      console.log('Users loaded to the database successfully ☺☺☺');
    } catch (err) {
      console.log(err);
    }
    process.exit();
  };
  
  const deleteData = async () => {
    try {
      await Review.deleteMany();
      console.log('Reviews successfully deleted');
  
      await Tour.deleteMany();
      console.log('Tours successfully deleted');
  
      await User.deleteMany({});
      console.log('Users successfully deleted');
    } catch (err) {
      console.log(err);
    }
  
    process.exit();
  };
  
  //console.log(process.argv);
  
  if (process.argv[2] === '--import') {
    importData();
  } else if (process.argv[2] === '--delete') {
    deleteData();
  }
  