This code validates to true no matter if the date is valid or not
const isValidDate = moment(isoFormattedDate).isValid();
// console.log(“isValidDate”, isValidDate)
if (isValidDate) {
res.json({ unix: Number(param), utc: utcTimeZone });
Your else that is for the invalid date is inside a condition that won’t allow it to handle the invalid date. Move it last, or have the function return that as the default value after all valid options have failed.
If no date payload is provided you must construct one using the current date.
Edit: Also the route parameter should be optional some/route/:param?, or you need a separate /api route for it. If you use the browsers dev tools you can inspect the request/response.
Not sure about your original question as your Replit no longer has that code and the code you posted isn’t enough to go on. I might also reconsider the lib anyway unless you really need it.