Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

document middleware in express

//4 types of middleware document,query,aggregate and model 
//document middleware run before .save() and .create()
const slugify = require('slugify')

tourSchema.pre('save',function(next) {
     console.log('will save document')
     this.slug= slugify(this.name,{lower:true})
     next()
})
Source by expressjs.com #
 
PREVIOUS NEXT
Tagged: #document #middleware #express
ADD COMMENT
Topic
Name
1+1 =