const express = require('express');
var router = express.Router()
const app = express();
const pgp = require('pg-promise')();
const pug = require('pug');
const connect = require('../core/connect.js');
const model = require('../models/model.js');
app.get('/data',function (req, res)
{
const data = model.getData(connect.db, 'Select * FROM items');
res.send(data);
});
Looking at the code here, I should be able to use the getData function from model because I required it within the actual get request to data. However for some reason, it does not seem to be performing the query. I have verified the data does exist through postgres. I also know that if I move the const data line out of the app.get, it also works.
Can someone please explain how I used my functions from the model.js file within GET and POST requests?
I'm not using Ajax or Jquery. I read through that article and I'm still not sure what exactly I'm missing. It is saying something about a callback, but I'm not too clear on that either.