Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 12, 2020 03:23 am GMT

Slack notifications with NodeJS in <2 minutes

When youre 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 youre part of a team, Slack is a great place to notify so that everyone is on the same page!

Getting started

Were going to use Taro to handle setting up this integration. Taro is a tool weve been working on, designed to make developers 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 youre 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 youd like to notify.

Once thats done, grab your API key by clicking Show next to the API key input above. Youll need that in a minute!

Creating a Slack notification in NodeJS

Now that youve 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, lets 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

Thats it!

By the way if youre having trouble with any of these steps, dont hesitate to leave a comment or reach out at [email protected].


Original Link: https://dev.to/reichert621/slack-notifications-with-nodejs-in-2-minutes-i7h

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To