Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Last active December 25, 2015 20:38
Show Gist options
  • Save mikermcneil/7036037 to your computer and use it in GitHub Desktop.
Save mikermcneil/7036037 to your computer and use it in GitHub Desktop.
Programmatic usage of sails (for testing, core testing, scheduled jobs, build scripts, etc.)
// NOTE:
// you may need to grab the latest version of Sails on the v0.10 branch for some of this to work
var sails = require('sails');
// You can do a lot here, but I'll show a few important ones
var options = {
// Completely disable globals (sails, your models, your services, _, async)
globals: false,
// Explicitly name the hooks you want to load:
// (all other hooks will be skipped)
loadHooks: ['moduleloader', 'userconfig', 'orm']
};
// Load Sails into memory so you can use it programatically
sails.load(options, function (err) {
if (err) sails.log('Encountered an error starting Sails:', err);
sails.log('Sails is ready to go!');
// sails.config
// sails.models
// sails.connections
// and so on
});
// Or if you use `lift`, it'll also start up the HTTP/WS servers:
sails.lift(options, function (err) {
//...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment