Hi everyone,
When using moment js on my application, I need to show users how long ago a post was created. For example, it should read like this: Created 2h ago.
For now it gives the specific time the post was created, which I really don’t fancy. For example, it reads like this: November 5, 2020 9:37 PM.
app.post('/created-posts', (req, res) => {
const timestamp = moment().format('LLL')
req.body.created = timestamp
db.collection('posts').insertOne(req.body, (err, result) => {
if (err) return console.log(err)
res.redirect('/')
})
})
This ‘created at’ value is being stored in a Mongdb database. Can anyone help on how I can make the database update itself, so the value can change with time.
The Mongodb snippet is as shown below:
id
:
5fa4548155d04d3718f3765a
name
:
"Jack"
body
:
"this is the body text"
created
:
"November 5, 2020 9:37 PM"
comments
:
Array