Skip to content
Advertisement

Build a function that returns events that are currently happening in the present within a selected time frame in NodeJs

I am fairly new in NodeJS, and I am trying to build an event management system where the user can see events that are happening now, upcoming events and past events. I have built a model called events which has attributes startDate and endDate which a user selects upon creation of an event. I need to list events that are happening in the present, this is the function I have built so far, however, it doesn’t work and I am pretty sure there is some mistakes in the syntax too. I would really appreciate anyone’s help on this 🙂

JavaScript

I tried writing a function (the one above) but I am new at JavaScript and I am a bit lost on how to make this work.

Advertisement

Answer

The logic is correct in this one, you just need to replace return eventPresent to res.status(200).json(eventPresent) – and put this outside the for loop, and also eventPresent.push(i) with eventPresent.push(event[i]), as you are only pushing the index into the array, and not the actual element as such:

JavaScript

Hope this helps! 🙂

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement