Slack has introduced ways to manage and send information via app. This method is still accurate and there hasn’t been any report regarding deprecating it anytime soon.
Slack have a very feature rich integration layer via smooth to set up WebHooks. It’s is even available to have a fully interactive message flow that deliver actions directly from the Slack chat to your application and also updates the messages depending on the return from your server.
This post will tell you how to send some custom error message or info messages to slack for notifications or history. slack webhook nodejs help you in how to create slack webhook and how to integrate it with nodejs helper.
Lets start the slack webhook api integration.
Three things you need it before this.
- Nodejs express project setup
- Slack package for nodejs
- Slack webhook
So for setting up nodejs express project i'm going into detail you can check my other article to use nodejs+express setup. I'm supposing that you already had a setup of project.
Second thing you need is slack npm package.
npm install winston winston-slack-webhook-transport --save
Third thing you need is slack webhook url . So please follow this weblink to generate webhook.
![]() |
slack webhook integration |
3.1 Add a new configuration so click on it to create new webhook. You also need to specify a channel or create a new one.

3.2 After that you need to specify your channel and create webhook.
After adding on incoming webhook it will give you a weblink save the link for further use.
Now lets come to the coding part. Now we are creating a helper function using winston logger . winston logger is provide you many transport hook like file logging, console logging and we are using slack logging feature.
Let's create notify.js in your nodejs project.Put your webhook in webhookUrl variable.
var winston = require('winston'); const { createLogger, format, transports } = require ('winston'); const SlackHook = require ('winston-slack-webhook-transport'); const moment = require ('moment'); var notify = createLogger ({ level: 'warn', timestamp: true, transports: [ new winston.transports.Console (), new SlackHook ({ webhookUrl: 'https://hooks.slack.com/services/TJ5JXXXXXJ/BPPPPPQXGV/XXXXXXXXHRzTZqpdOtaDUzj8', formatter: info => { return { text: `*${process.env.name}*:*${process.env.NODE_ENV}* => ${info.level}: ${info.message}`, }; }, username: 'WantCodeBot', }), ], });
const notify = require('../../../helpers/notify'); notify.warn( `this api throw error \n> *request*: \n>${JSON.stringify(req.body)} *response*: ${JSON.stringify(response)}` );
Now visit slack you will see a new notification in your channel. isn't it cool.