Edit Page

api/services

Purpose

This folder contains your services. 'Services' are similar to controller actions but are typically used for things that don't necessarily have to happen between the time when the user sends a request and when the server sends back a response. Any logic that doesn't rely on .req() and .res() can be turned into a service if for no other reason than to keep your controllers clean and manageable.

Hypothetically, one could create a service for

  • Sending emails
  • Automating tweets to celebrities
  • Retrieving data from a third party API then pushing that data to your client WHEN IT'S READY (over websockets)

Services are written in one or more .js file within this directory.

Example Email.js

module.exports = {
  send: function(to,from,body){
    // fancy code that sends an email
  }
}

You would call this service with Email.send('rick','bill','lol')

Mind your case. Email.send !== email.send

Want to see for yourself?

An example of this directory can be found in our sample app repo, here.

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

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

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

App Structure


  • api
    • controllers
      • .gitkeep
      • UserController.js
    • hooks
      • myHook
        • index.js
    • models
      • .gitkeep
      • User.js
    • policies
      • sessionAuth.js
    • responses
      • badRequest.js
      • forbidden.js
      • notFound.js
      • ok.js
      • serverError.js
    • services
      • .gitkeep
  • assets
    • images
      • .gitkeep
    • js
      • dependencies
        • sails.io.js
    • styles
      • importer.less
    • templates
      • .gitkeep
    • favicon.ico
    • robots.txt
  • config
    • env
      • production.js
    • locales
      • de.json
      • en.json
      • es.json
      • fr.json
    • blueprints.js
    • bootstrap.js
    • connections.js
    • cors.js
    • csrf.js
    • globals.js
    • http.js
    • i18n.js
    • local.js
    • log.js
    • models.js
    • policies.js
    • routes.js
    • session.js
    • sockets.js
    • views.js
  • tasks
    • config
      • clean.js
      • coffee.js
      • concat.js
      • copy.js
      • cssmin.js
      • jst.js
      • less.js
      • sails-linker.js
      • sync.js
      • uglify.js
      • watch.js
    • register
      • build.js
      • buildProd.js
      • compileAssets.js
      • default.js
      • linkAssets.js
      • linkAssetsBuild.js
      • linkAssetsBuildProd.js
      • prod.js
      • syncAssets.js
    • pipeline.js
    • README.md
  • views
    • 403.ejs
    • 404.ejs
    • 500.ejs
    • homepage.ejs
    • layout.ejs
  • .gitignore
  • .sailsrc
  • app.js
  • Gruntfile.js
  • package.json
  • README.md

Built with Love

The Sails framework is maintained by a web & mobile studio 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?
  • Treeline IDE
  • Contribute
  • Logos/artwork
About:
  • The Sails Company
  • Security
  • News
  • Legal
Help:
  • Get started
  • Documentation
  • Docs
  • Enterprise
  • Hire us

© 2012-2018 The Sails Company. 
The Sails framework is free and open-source under the MIT License.