text: const path = require('path');
  const express = require('express');
  const MongoClient = require('mongodb').MongoClient;
  const ObjectId = require('mongodb').ObjectId;
  const app = express();
  app.use(express.json());
  
  /// YOUR ROUTES GO HERE!
  
  
  /////////////////////////////////////////////
  
  // Totally insecure backend routes below, good only for rapid prototyping
  // unsecured front-end applications. Should not be used in production.
  
  
  // GET for getting existing item
  app.get('/api/mongodb/:collectionName/', (request, response) => {
    const collectionName = request.params.collectionName;
  
    // Get GET params, if there are any
    const query = request.query || {};
  
    // Due to a requirement of MongoDB, whenever we query based on _id field, we
    // have to do it like this using ObjectId
    if (query._id) {
      query._id = ObjectId(query._id);
    }
  
    db.collection(collectionName)
      .find(query)
      .toArray((err, results) => {
        // Got data back.. send to client
        if (err) throw err;
        response.json(results);
      });
  });
  
  // POST for creating a new item
  app.post('/api/mongodb/:collectionName/', (request, response) => {
    const collectionName = request.params.collectionName;
    const data = request.body;
  
    db.collection(collectionName)
      .insert(data, (err, results) => {
        // Got data back.. send to client
        if (err) throw err;
  
        response.json({
          'success': true,
          'results': results,
        });
      });
  });
  
  
  // PUT endpoint for modifying an existing item
  app.put('/api/mongodb/:collectionName/', (request, response) => {
    const collectionName = request.params.collectionName;
    const data = request.body;
    const query = request.query;
  
    // Due to a requirement of MongoDB, whenever we query based on _id field, we
    // have to do it like this using ObjectId
    if (query._id) {
      query._id = ObjectId(query._id);
    }
  
    db.collection(collectionName)
      .updateOne(query, {$set: data}, (err, results) => {
        if (err) throw err;
  
        // If we modified exactly 1, then success, otherwise failure
        if (results.result.nModified === 1) {
          response.json({
            success: true,
          });
        } else {
          response.json({
            success: false,
          });
        }
      });
  });
  
  
  // D in CRUD, delete a single item with given criteria
  app.delete('/api/mongodb/:collectionName/', (request, response) => {
    const collectionName = request.params.collectionName;
    const query = request.query;
  
    // Due to a requirement of MongoDB, whenever we query based on _id field, we
    // have to do it like this using ObjectId
    if (query._id) {
      query._id = ObjectId(query._id);
    }
  
    db.collection(collectionName)
      .deleteOne(query, (err, results) => {
        if (err) throw err;
  
        // If we deleted exactly 1, then success, otherwise failure
        if (results.result.n === 1) {
          response.json({
            success: true,
          });
        } else {
          response.json({
            success: false,
          });
        }
      })
  });
  
  
  
  
  
  
  
  /////////////////////////////////////////////
  // Boilerplate, no need to touch what's below
  
  /////////////////////////////////////////////
  // Logger & configuration
  function logger(req, res, next) {
    console.log(req.method, req.url);
    next();
  }
  app.use(logger);
  /////////////////////////////////////////////
  
  
  // For production, handle any requests that don't match the ones above
  app.use(express.static(path.join(__dirname, 'client/build')));
  
  // Wild-card, so handle everything else
  app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '/client/build/index.html'));
  });
  
  
  // Set up configuration variables
  if (!process.env.MONGODB_URI) {
    console.log('- Error - Must specify the following env variables:');
    console.log("MONGODB_URI='mongodb://someUser:somePW@site.com:1234/someDB'");
    console.log('- (See README.md)');
    process.exit(1);
  }
  const MONGODB_URL = process.env.MONGODB_URI;
  const splitUrl = MONGODB_URL.split('/');
  const mongoDbDatabaseName = splitUrl[splitUrl.length - 1];
  
  let db;
  // First connect to MongoDB, then start HTTP server
  MongoClient.connect(MONGODB_URL, {useNewUrlParser: true}, (err, client) => {
    if (err) throw err;
    console.log("--MongoDB connection successful");
    db = client.db(mongoDbDatabaseName);
  
    // Start the server
    const PORT = process.env.PORT || 8080;
    app.listen(PORT, () => {
      console.log(`
        *********************************************
        * Insecure prototyping backend is running!  *
        * Only use for prototyping                  *
        * Backend server up at ${PORT}              *
        *********************************************
      `);
    })
  });
  
  // export MONGODB_URI='mongodb://susaposa:mortadelo@6365@cluster0-ovkkm.mongodb.net:27017/mydb'
  
  // export MONGODB_URI='mongodb+srv://susana:mortadelo6365@cluster0-ovkkm.mongodb.net/mydb'