View our GitHub

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

Edit Page

Creating a Service?

Simply save a Javascript file containing a function or object into your api/services folder. The filename will be used as the globally-accessible variable name for the service. For example, an email service might look something like this:

// EmailService.js - in api/services
module.exports = {

    sendInviteEmail: function(options) {

        var opts = {"type":"messages","call":"send","message":
            {
                "subject": "YourIn!",
                "from_email": "[email protected]",
                "from_name": "AmazingStartupApp",
                "to":[
                    {"email": options.email, "name": options.name}
                ],
                "text": "Dear "+options.name+",\nYou're in the Beta! Click <insert link> to verify your account"
            }
        };

        myEmailSendingLibrary.send(opts);

    }
};

You can then use EmailService anywhere in your app:

// Somewhere in a controller
  EmailService.sendInviteEmail({email: '[email protected]', name: 'test'});

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.