A Sails hook that provides diagnostic / debugging information during development.
Check the memory usage or environent variables of the currently-running Sails/Node.js process. Or check how it's configured, or the installed versions of its dependencies. You can also fetch session data for the currently logged in user, or force Node's garbage collector to run.
The diagnostic routes exposed by this hook will work when your app is in development mode (i.e.
If you want to enable this hook in a production-like environment where NODE_ENV is set to production (such as your staging environment), then use the
For security reasons, this hook should never be used in a true production environment that touches real users.
In your Sails project:
npm install sails-hook-dev --save-dev
^^ That will install this hook as a dev dependency, for local development only. If you also want to use sails-hook-dev somewhere else (like in your staging environment), then instead use:
npm install sails-hook-dev
To see all available development routes, visit http://localhost:1337/dev:
See all available routes
See session of currently logged-in user
See actual versions of dependencies in
See current memory usage
Deliberately crash the process
Simulate endpoint that never sends a response
Simulate locking up the process by overwhelming its CPU
Simulate runaway recursion that overflows the call stack
Simulate exceeding the process's available memory
Simulate an endpoint that consumes memory, but does not leak
Simulate an endpoint with an actual memory leak
Run the garbage collector
Note that you must lift your app with
node --expose-gc app.jsin order for the garbage collector to be accessible from userland.
Setting this up on your staging server
Want to use this hook in your staging environment? Since the NODE_ENV environment variable will be set to production, the hook will be disabled by default. But never fear: there is a simple, recommended solution.
At the bottom of your staging configuration (
Note that you could hypothetically specify this in your environment variables, by setting
sails_dev__enableInProduction=true. But as of Sails 1.1.0 the behavior of
rcwhen merging this particular config key gets a little bit wonky, so it's best to stick with the solution above.
If you have further questions or are having trouble, click here.
To report a bug, click here.
Please observe the guidelines and conventions laid out in the Sails project contribution guide when opening issues or submitting pull requests.
MIT © 2015, 2016, 2018-present Mike McNeil