Serving json from a file express js

Viewed 8008

Newbie to express, I have a folder that has a db.json file and it gets replaced with a new db.json every 11 seceonds. What is the best way to let express.js serve it so that new content shows on api call? This is what I have so far:

const express = require('express');
const router = express.Router();

router.get('/api/items', (req, res) => {
  let dbPath = require('./data/db.json');
  res.send(JSON.stringify(dbPath));

});

db.json looks something like this

[{"recordType": "E90", "count": "55", "space": "4" },
{"recordType": "A48", "count": "40", "space": "5" }, ....]

Problem: I'm not seeing the updated value next time I make the api call.

1 Answers
Related