You can use sails-generate
from the Sails command line tool to quickly generate a controller, or even just an individual action.
For example, to generate a controller:
$ sails generate controller user
Sails will generate api/controllers/UserController.js
:
/**
* UserController.js
*
* @description :: Server-side controller action for managing users.
* @help :: See https://sailsjs.com/documentation/concepts/controllers
*/
module.exports = {
}
Run the following command to generate a standalone action:
$ sails generate action user/signup
info: Created an action!
Using "actions2"...
[?] https://sailsjs.com/docs/concepts/actions
Sails will create api/controllers/user/sign-up.js
:
/**
* user/sign-up.js
*
* @description :: Server-side controller action for handling incoming requests.
* @help :: See https://sailsjs.com/documentation/concepts/controllers
*/
module.exports = {
friendlyName: 'Sign up',
description: '',
inputs: {
},
exits: {
},
fn: function (inputs, exits) {
return exits.success();
}
};
Or, using the classic actions interface:
$ sails generate action user/signup --no-actions2
info: Created a traditional (req,res) controller action, but as a standalone file
Sails will create api/controllers/user/sign-up.js
:
/**
* Module dependencies
*/
// ...
/**
* user/signup.js
*
* Signup user.
*/
module.exports = function signup(req, res) {
sails.log.debug('TODO: implement');
return res.ok();
};