Issue Tracker, Connecting to Database

I’ve been having a difficult time understanding how to save data from my routes to my database. I think using modules has thrown me off to some degree.

If I move my MongoClient.connect statement under module exports and use it to enclose my routes, all the routes will fail to work. And the page for the route will say ‘Not Found’ if one were to navigate to it. As of currently I have moved it back to its original place and I am just feeling puzzled about what I need to do next.

The database itself works correctly if I attempt any CRUD operations as it is currently situated, and the routes on their own also work correctly.

Thank you so much for any help or guidance.

var expect = require('chai').expect;
var MongoClient = require('mongodb');
var ObjectId = require('mongodb').ObjectID;

const CONNECTION_STRING = process.env.DB; 

MongoClient.connect(CONNECTION_STRING, {
  useNewUrlParser: true, 
  useUnifiedTopology: true }, 
  function(err, db) {
   
    const myDB = db.db('library').collection('issues');
   }); //end of connect


module.exports = function (app) {

app.route('/api/issues/:project')
...

}

Hey Lei,

Can you tell us, how you think the logical steps behind the whole approach works?

E.g.

  1. User inputs their data (title, text, created by etc.) and clicks Submit
  2. Frontend sends POST request to X
  3. ???