-1
res.cookie("cookieJWT", accessToken, {
  secure: false, 
  httpOnly: true,
  expires: // This needs a javascript date object, how do I create one for tomorrow?
});

Can plain nodeJS do this? Or do I need to download some modules?

snak
  • 5,713
  • 3
  • 21
  • 32
Oscar
  • 77
  • 6

1 Answers1

0

This would work if you mean 24 hours later by "tomorrow".

new Date(Date.now() + 24 * 60 * 60 * 1000);

If you mean the beginning of tomorrow, you can do this. But note that the current timezone affects the result in this case.

const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate());
snak
  • 5,713
  • 3
  • 21
  • 32
  • Adding 24 hours doesn't necessarily get a date for tomorrow as where daylight saving is observed one day per year is longer than 24 hours and one is shorter. See [*How can I add 1 day to current date?*](https://stackoverflow.com/questions/9989382/how-can-i-add-1-day-to-current-date) – RobG Mar 03 '22 at 10:03