Back End Development and APIs Projects - Exercise Tracker

It seems that when I try to change the code any way it doesn’t pass the first 6 tests. I’ve been stuck on this for almost 2 weeks. I have no idea how I can fix it or what needs to be done. Any help is appreciated

Your project link(s)

solution: boilerplate-project-exercisetracker-1 - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

You need to look at your Node console. I see:

ReferenceError: newDate is not defined

It seems when I edit it, it makes it fail the second test and it still doesn’t pass

I just had the first 6 tests past but, now for some reason the second one isn’t passing anymore again. I have no idea what could be wrong

I would suggest you install nodemon and change the start script to use it instead of node. That way when the server crashes it will not auto restart and you can actually read the crash log (not sure who on the Replit team thought auto restarting a server that crashes and wiping the log was a good idea but it is just dumb).

It is crashing with TypeError: Cannot read properties of null (reading 'toJSON')

Log out req.query in the /api/users/:_id/logs route. hint: :id is a parameter, i.e. req.params

As an aside, Line 63: toDateString is a method you have to call it ()

There still seems to be an error. Even when I do that. I ran nodemon and there is still errors. I had 7 of the tests pass but then whenever I make any slight changes it then fails everything.

I don’t see nodemon in your project and you have a syntax error (line 67). If I add nodemon and fix the syntax error I get a new error. If I fix that I get the same error from before, your parameter is not named userId. I’d suggest you log out req.params in your routes.

Log out req.body._id inside the /api/users/:_id/exercises route, or just req.body and look at it.

Log out req.params.userId inside the /api/users/:_id/logs route, or just req.params and look at it.

I’ve tried fixing it but, it’s still giving the same error.

You really need to learn how to debug your project. One of the first tests you are failing is:

You can POST to /api/users/:_id/exercises with form data description , duration , and optionally date . If no date is supplied, the current date will be used.

Have you actually tried to send a post request with an existing _id using the 2nd form of index.html? If you do that, you will see the following error in the Node console pop up.

TypeError: Cannot read properties of null (reading 'id')
    at /home/runner/boilerplate-project-exercisetracker-2/index.js:81:33
    at /home/runner/boilerplate-project-exercisetracker-2/node_modules/mongoose/lib/model.js:4931:18
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
Emitted 'error' event on Function instance at:
    at /home/runner/boilerplate-project-exercisetracker-2/node_modules/mongoose/lib/model.js:4933:15
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
exit status 1

Do you understand why line 81 (seen below) causes this error?


The real source of why you are failing the test is the following:

USER.findByIdAndUpdate (

I suggest adding console.log(req.body._id)before the call toUSER.findByIdAndUpdate`. You may be surprised at what the value is.

I see it says undefined, so I’ve fixed that part and now it’s the response return. I see the problem now. This post can be closed now.