Jaseem Abbas
Jaseem Abbas

Reputation: 5230

Is it possible to group services in sails using subfolders?

Is it possible to group services files into subfolders under services in sails.js? This speaks about grouping controllers. How do I do the same for services?

Upvotes: 1

Views: 544

Answers (1)

elssar
elssar

Reputation: 5871

You could try something like this

  • services/
    • FooBar/
      • foo.js
      • bar.js
    • FooBarService.js

Your FooBarService.js should just require everything inside FooBar/

/**
 * FooBarService
 */

module.exports = {
    foo: require('FooBar/foo.js'),
    bar: require('FooBar/bar.js')
};

Or if you want to make it more sails-y, use include-all. It is include in all sails projects, and is used everywhere in sails

/**
 * FooBarService
 */

module.exports = require('include-all')({
    dirname: __dirname + '/FooBar',
    filter: /.+\.js$/
});

Upvotes: 1

Related Questions