DEV Community

Alex Reichert
Alex Reichert

Posted on

Slack notifications with NodeJS in <2 minutes

When you’re working on a project, it can be useful to set up a simple notification system for a number of reasons:

  • You want to be notified whenever a new user signs up 🚀
  • You want to be alerted when a user encounters an unexpected error 🤔
  • You want to be reminded every morning to fill out your TODO list

If you’re part of a team, Slack is a great place to notify so that everyone is on the same page!

Getting started

We’re going to use Taro to handle setting up this integration. Taro is a tool we’ve been working on, designed to make developer’s lives easier when it comes to this kind of thing.

To start, create your free account at https://www.gettaro.com/ by clicking the “Get started” button and signing up.

Connecting to Slack

Once you’re in the dashboard, click on the “Integrations” button in the upper-right corner of the page. You should see something like this:

Taro Integrations Page

At the bottom of the page, click on “Connect with Slack”, and complete that flow with the Slack channel you’d like to notify.

Once that’s done, grab your API key by clicking “Show” next to the API key input above. You’ll need that in a minute!

Creating a Slack notification in NodeJS

Now that you’ve set up a link to your Slack channel and gotten your API key, you can either set up a new Node project, or use an existing one. For the sake of this guide, let’s create a quick new one.

In a new project directory, run npm init, and keep pressing enter until your package.json file is set up with all the default values. It should look something like this (mine happened to be in a directory called “sandbox”):

New NodeJS project

Then, create an index.js file, and paste in the code below — remember to replace __YOUR_API_KEY__ with your API key from above 🤓

Run the code

In your terminal, run node index.js — you should receive a notification in Slack! 🎉

Slack notification

That’s it!

By the way — if you’re having trouble with any of these steps, don’t hesitate to leave a comment or reach out at reichertjalex@gmail.com.

Oldest comments (1)

Collapse
 
abelardoit profile image
abelardoit

Hi there,

IMHO, the problem here is we pay with our privacy since we use a third party platform to quickly deliver our notifications. A "middleware" more.

Nice article but useless for me. :) Thanks. Best regards.