I have a question consisting of two parts:
Thanks,
TM
Services are stateless libraries of functions that you can use from anywhere in your Sails app. For example, you might have an EmailService which tidily wraps up one or more utility functions so you can use them in more than one place within your application.
To create a new Sails application, run the sails new command passing in the name of your application. This command will both generate a new Sails app and run npm install to install all dependencies for you.
a service would be in my opinion, a piece of logic that you need in multiple locations of your app. for example an email service. the following is taken directly from the sails-wiki github page.
// EmailService.js - in api/services
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);
};
The wiring is done by sails itself:
// Somewhere in a conroller
EmailService.sendInviteEmail({email: '[email protected]', name: 'test'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With