View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

sails generate

Sails ships with several generators to help you scaffold new projects. You can also create your own generators to handle frequent tasks, or extend functionality (for example, by creating a generator that outputs view files for your favorite templating language).

The following generators are bundled with Sails:

sails generate new <appName>

Create a new Sails project in a folder called appName. See sails new for usage options.

sails generate api <foo>

Generate api/models/Foo.js and api/controllers/FooController.js

sails generate model <foo> [attribute1:type1, attribute2:type2 ... ]

Generate api/models/Foo.js, optionally include attributes with the specified types.

sails generate controller <foo> [action1, action2, ...]

Generate api/controllers/FooController.js, optionally include actions with the specified names.

sails generate adapter <foo>

Generate a api/adapters/foo folder containing the files necessary for building a new adapter.

sails generate generator <foo>

Generate a foo folder containing the files necessary for building a new generator.

Coffeescript support

If you want to use Coffeescript for write your controllers or models even config files; just follow these steps:

  1. Install Coffeescript locally and save it in your package.json file:
    npm install --save coffee-script
    
  2. Install the generators for Coffeescript (optional):
    npm install --save-dev sails-generate-controller-coffee sails-generate-model-coffee
    
  3. To generate scaffold code, add --coffee:
    sails generate api <foo> --coffee
    # Generate api/models/Foo.coffee and api/controllers/FooController.coffee
    sails generate model <foo> --coffee
    # Generate api/models/Foo.coffee
    sails generate controller <foo> --coffee
    # Generate api/controllers/FooController.coffee
    

Thats it, now you can write your code using Coffeescript!

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book