Skip to content

Instantly share code, notes, and snippets.

@ndabAP
Last active June 28, 2017 04:52
Show Gist options
  • Save ndabAP/1dfa9a033af7979f7b18e019a3028786 to your computer and use it in GitHub Desktop.
Save ndabAP/1dfa9a033af7979f7b18e019a3028786 to your computer and use it in GitHub Desktop.
Use nested services instead of helpers within Sails.js 1.0
// config/bootstrap.js
module.exports.bootstrap = function (done) {
const path = require('path')
// Install the required package first
sails.services = require('include-all')({
dirname: path.resolve('api/services'),
filter: /(.+Service)\.js$/,
excludeDirs: /^\.(git|svn)$/
})
return done()
}
// api/controllers/SomeController.js
module.exports = {
/**
* @param req
* @param res
*/
create: (req, res) => {
let love = sails.services.SomeService.getLove()
}
}
// api/services/SomeService.js
module.exports = {
getLove: () => {
return 'Love'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment