Lennox C. Charles

Hack. Develop. Write

How to monitor your Sails application with Slack.

A simple Sails hook to help you send messages to slack from your Sails application. It also comes with a helper function to send messages directly to slack without necessary logging it.

Monitoring your Sails application has never been easier! In this article I will show you how to setup your Sails application with Slack.

Prerequisites

Installation

npm install sails-hook-slack

Usage

To use the Slack hook in your Sails.js application, add the following configuration to your config/slack.js file:

module.exports.slack = {
  webhookUrl: process.env.SLACK_WEBHOOK_URL,
  defaultUsername: process.env.SLACK_DEFAULT_USERNAME,
  defaultIcon: process.env.SLACK_DEFAULT_ICON,
  logLevels: process.env.SLACK_LOG_LEVELS,
};

Configuration

Bonus

There is a helper function sails.helpers.slack that you can use to send messages to Slack directly without logging the message.

sails.helpers.slack("Hello from Sails!", {
  username: "Sails",
  icon: ":boom:",
});

The username and icon options are optional. If not passed then the default values will be used.

That’s it!

That’s all it takes to monitor your Sails application with slack. See you on the next one.