text: //const apiRoutes = require('./routes/apiRoutes');
  //const htmlRoutes = require('./routes/htmlRoutes');
  const express = require("express");
  const path = require("path");
  const fs = require("fs");
  const PORT = process.env.PORT || 3001;
  const app = express();
  const mainDir = path.join(__dirname, "/public");
  
  app.use(express.static('public'));
  // parse incoming string or array data
  app.use(express.urlencoded({extended: true}));
  // parse incoming json data
  app.use(express.json());
  // app.use('/api', '/', htmlRoutes);
  // app.use('/', htmlRoutes);
  
  app.get("/api/notes", function(req, res) {
      res.sendFile(path.join(__dirname, "/db/db.json"));
    });
    
  app.get("/api/notes/:id", function(req, res) {
      let savedNotes = JSON.parse(fs.readFileSync("/db/db.json", "utf8"));
      res.json(savedNotes[Number(req.params.id)]);
    });
  
  app.get("/notes", function(req, res) {
      res.sendFile(path.join(mainDir, "notes.html"));
    });
    
  app.get("*", function(req, res) {
      res.sendFile(path.join(mainDir, "index.html"));
    });
    
  app.post("/api/notes", function(req, res) {
      let savedNotes = JSON.parse(fs.readFileSync("./db/db.json", "utf8"));
      let newNote = req.body;
      let uniqueID = (savedNotes.length).toString();
      newNote.id = uniqueID;
      savedNotes.push(newNote);
    
      fs.writeFileSync("./db/db.json", JSON.stringify(savedNotes));
      console.log("Saved to:", newNote);
      res.json(savedNotes);
    })
    
  app.delete("/api/notes/:id", function(req, res) {
      let savedNotes = JSON.parse(fs.readFileSync("./db/db.json", "utf8"));
      let noteID = req.params.id;
      let newID = 0;
      console.log(`Deleting note: ${noteID}`);
      savedNotes = savedNotes.filter(currNote => {
          return currNote.id != noteID;
      })
      
      for (currNote of savedNotes) {
          currNote.id = newID.toString();
          newID++;
      }
    
      fs.writeFileSync("./db/db.json", JSON.stringify(savedNotes));
      res.json(savedNotes);
    })
  
  app.listen(PORT, () => {
      console.log(`API server now on port ${PORT}!`);
    });