by navid.behroozimajd78@gmail.com

New About Yours API Help
851 bytes, JavaScript
// Model:
const filePath = path.join(
  path.dirname(process.mainModule.filename),
  "data",
  "items.json"
);
const readContentFromFile = cb => {
  fs.readFile(filePath, (err, fileContent) => {
    if (err) {
      cb([]);
    }
    cb(JSON.parse(fileContent));
  });
};
static fetchOneItem(id, cb) {
    readContentFromFile(items => {
      const findId = items.find(p => {
        return p.id === id;
      });
      console.log(findId);
      cb(findId);
    });
  }




// Controller:
module.exports.createItemDetailsPage = (req, res) => {
  const myItemId = req.params.itemId;
  ItemModel.fetchOneItem(myItemId, items => {
    res.render("details", {
      pageTitle: "item.title",
      item: items
    });
  });
};




// Router:
router.get("/details/:itemId", itemsControllers.createItemDetailsPage);
Pasted 1 month, 1 week ago — Expires in 325 days
URL: http://dpaste.com/3AA767V