Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create slug 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()
})
 
PREVIOUS NEXT
Tagged: #create #slug #express
ADD COMMENT
Topic
Name
8+7 =