Edit Page

Using CoffeeScript in a Sails app

The recommended language for building Node.js+Sails apps is JavaScript.

But Sails also supports using CoffeeScript to write your custom app code (like actions and models). You can enable this support in three steps:

  1. Run npm install coffee-script --save in your app folder.
  2. Add the following line at the top of your app's app.js file:
    require('coffee-script/register');
    
  3. Start your app with node app.js instead of sails lift.

Using CoffeeScript generators

If you want to use CoffeeScript to write your controllers, models or config files, just follow these steps:

  1. Install the generators for CoffeeScript (optional):
    npm install --save-dev sails-generate-controller-coffee sails-generate-model-coffee
  2. To generate scaffold code, add --coffee when using one of the supported generators from the command-line:
    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
    

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 repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Sails logo
  • Home
  • Get started
  • Support
  • Documentation
  • Documentation

For a better experience on sailsjs.com, update your browser.

Check out the full Sailsconf 2022 playlist on Youtube

Tweet Follow @sailsjs

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Tutorials

  • Full-stack JavaScript with Sails
  • Low-level MySQL usage (advanced)
  • Using CoffeeScript
  • Using MongoDB
  • Using TypeScript

Built with Love

The Sails framework is built by a web & mobile shop in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!

Sails:
  • What is Sails?
  • Community
  • News
  • For business
About:
  • Our company
  • Security
  • Legal
  • Logos/artwork
Help:
  • Get started
  • Documentation
  • Docs
  • Contribute
  • Take a class

© 2012-2022 The Sails Company. 
The Sails framework is free and open-source under the MIT License. 
Illustrations by Edamame.