Tuesday, 18 August 2020

Why does this express route say .slice is not a function?

HelloHere is the code to the route I am having trouble withapp.get('/posts', (req, res) => {const page = req.query.pageconst limit = req.query.limitconst startIndex = (page - 1) * limitconst endIndex = page * limitresult = json.slice(startIndex, endIndex)res.json(result)});I also imported a json file as jsonconst json = require(./posts.json)I've been trying to figure out why it won't work, but I honestly don't understand what's wrong. Any tips? Thanks!

Submitted August 18, 2020 at 02:01PM by LGm17

No comments:

Post a Comment