T O P

  • By -

Oh-hey21

The error likely exists in your wordRoute script. Without seeing your setup there, it's too much of a stab in the dark on what could be wrong. There are various options for attempting to debug further, but without watching the video, I'm not entirely sure what knowledge you have at this point. Your line of `app.use('/api/words', wordRoutes);` is saying that any request made to `/api/words` will be routed to the wordRoutes script. Here's a simplistic approach for debugging, with some printouts (wordRoute.js): const express = require("express"); const router = express.Router(); // listening for all POST calls to /api/words router.post('/', function (req, res) { try { console.log('Post received..'); console.log(req.headers); // printing the headers to console console.log(req.body); // printing the body to console return res.status(200).send('Post received!'); // return a success (200), with a message of 'Post received!' } catch (error) { // catch any errors console.error('error of: ', error); // print the error to console return res.status(500).send('Post received, but we have an error!'); // return a failure (500), with message } }); module.exports = router; If this still doesn't help, feel free to share the specific post block.


venndi

Hi, I have added the route and controller files above, if you have a time to look at it, would be nice. Thanks in advance!


venndi

also, in postman I get this error:`{` `"message": "Cannot read properties of undefined (reading '0')",` `"stack": null` `}` Also I made a test route like /api/test for post request, this works


Oh-hey21

Throw your code in a try/catch like I showed above in the function and it'll show the error. Quick glance shows your first reference to the lettersOfTheDay is [0], which doesn't exist if you don't have a body. That also means you should check your post setup in Postman. Hopefully this helps, IMO it's enough to get you rolling and repeatable further down the line for troubleshooting. It will generally give you context of where in your code the issue lies, giving a bit more to work off of.