Project hooks are custom Sails hooks that reside in an application’s
api/hooks folder. They are typically useful when you want to take advantage of hook features like defaults and routes for code that is used by multiple components in a single app. If you wish to re-use a hook in more than one Sails app, see creating an installable hook instead.
To create a new project hook:
index.jsfile to that folder.
index.jsin accordance with the hook specification.
Your new folder may contain other files as well, which can be loaded in your hook via
index.js will be read automatically by Sails.
As an alternative to a folder, you may create a file in your app’s
api/hooks folder like
To test that your hook is being loaded by Sails, lift your app with
sails lift --verbose. If your hook is loaded, you will see a message like:
verbose: your-hook-name hook loaded successfully.
in the logs.