Karl Bateman Karl Bateman - 2 months ago 6x
Node.js Question

Creating a new date using momentjs within a nodejs consumer

I have a NodeJS RabbitMQ consumer which creates a date using MomentJS. However because this runs constantly, the date is always the same.

How can I create a new date every time the consumer receives a message?
Should I wrap the call to

within a function or do I need to use
new moment.format()


This could be done by initializing a new date when receiving a new message like

let newDate = new moment()

Edit: Also working without the new keyword

let newDate = moment()

but better for readability and preventing some possible strange effects

let newDate = moment(new Date())