
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
captain-hook
Advanced tools
Pre- and Post- Create and Update Hooks for Mongoose ODM.
Out of the box, Mongoose provides you with the handy pre('save')
and post('save')
methods. Unfortunately, these hooks run every time the instance is saved, whether it is being created or updated. Captain Hook extends Mongoose to give you greater control over this functionality.
npm install captain-hook --save
In your Mongoose model:
var captainHook = require('captain-hook');
var userSchema = mongoose.Schema();
userSchema.plugin(captainHook);
// function to run before saving a new user instance
userSchema.preCreate(function(user, next){
console.log("You are about to create a user:" + user.email);
next();
})
// function to run after saving a new user instance
userSchema.postCreate(function(user, next){
console.log("You just created a user:" + user.email);
next();
})
// function to run before updating an existing user instance
userSchema.preUpdate(function(user, next){
console.log("You are about to update a user:" + user.email);
next();
})
// function to run before updating an existing user instance
userSchema.postUpdate(function(user, next){
console.log("You just updated a user:" + user.email);
next();
})
Multiple pre- and post- methods can be added for each timing (preCreate, postCreate, preUpdate, postUpdate) and the functions will be run in the order they are defined.
The next()
callback must be called for every hook.
FAQs
Pre- and Post- Create and Update Hooks for Mongoose ODM
We found that captain-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.