{"id":12041,"library":"slack-node","title":"Slack Node.js SDK","description":"slack-node is a Node.js library for interacting with the Slack API, supporting both incoming webhooks and the comprehensive Slack Web API. Currently at version 0.3.2, it maintains a policy of zero runtime dependencies, making it a lightweight choice for integrating Slack functionalities into Node.js applications. The library is designed for flexibility, offering both traditional callback-based asynchronous operations and modern Promise-based and async/await syntax, catering to various coding styles. While its version number suggests a pre-1.0 stability, the project claims continuous updates and full feature support. Its core differentiation lies in its minimalist approach to dependencies and its dual API consumption models.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/clonn/slack-node-sdk","tags":["javascript","slack","node","sdk"],"install":[{"cmd":"npm install slack-node","lang":"bash","label":"npm"},{"cmd":"yarn add slack-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add slack-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library is CommonJS-only. Use `require()` for importing the `Slack` class. ESM `import` statements are not natively supported and will fail without a transpilation step.","wrong":"import Slack from 'slack-node';","symbol":"Slack","correct":"const Slack = require('slack-node');"},{"note":"For webhook usage, an instance is created without an API token, and the webhook URL must be explicitly set via `setWebhook()`.","symbol":"Slack instance (webhook)","correct":"const slack = new Slack();\nslack.setWebhook('__your_webhook_url__');"},{"note":"For Slack Web API calls, the API token should be passed directly to the constructor when creating the `Slack` instance.","symbol":"Slack instance (API)","correct":"const slack = new Slack('__your_api_token__');"}],"quickstart":{"code":"const Slack = require('slack-node');\n\nasync function main() {\n  // Webhook usage\n  const webhookUrl = process.env.SLACK_WEBHOOK_URL ?? '__your_webhook_url__';\n  const slackWebhook = new Slack();\n  slackWebhook.setWebhook(webhookUrl);\n\n  if (webhookUrl === '__your_webhook_url__') {\n    console.warn(\"Please provide a valid SLACK_WEBHOOK_URL environment variable or replace the placeholder.\");\n  } else {\n    try {\n      const webhookResponse = await slackWebhook.webhook({\n        channel: \"#general\",\n        username: \"webhookbot\",\n        text: \"Hello from async/await via webhook!\",\n        icon_emoji: \":ghost:\"\n      });\n      console.log(\"Webhook message sent:\", webhookResponse.data);\n    } catch (err) {\n      console.error(\"Webhook error:\", err);\n    }\n  }\n\n  // API usage\n  const apiToken = process.env.SLACK_API_TOKEN ?? '__your_api_token__';\n  if (apiToken === '__your_api_token__') {\n    console.warn(\"Please provide a valid SLACK_API_TOKEN environment variable or replace the placeholder.\");\n  } else {\n    const slackApi = new Slack(apiToken);\n    try {\n      const usersList = await slackApi.api(\"users.list\");\n      console.log(\"Users list:\", usersList.members.map(u => u.real_name));\n\n      const chatPostMessage = await slackApi.api(\"chat.postMessage\", {\n        text: \"hello from async/await via API\",\n        channel: \"#general\"\n      });\n      console.log(\"API message sent (timestamp):\", chatPostMessage.ts);\n    } catch (err) {\n      console.error(\"API error:\", err);\n    }\n  }\n}\n\nmain();","lang":"javascript","description":"Demonstrates sending a message via an Incoming Webhook and calling a Slack Web API method (users.list and chat.postMessage) using `async/await` syntax, utilizing environment variables for credentials."},"warnings":[{"fix":"Always use `const Slack = require('slack-node');` to import the library. If using TypeScript, ensure your `tsconfig.json` has `\"module\": \"commonjs\"` or configure your bundler/runtime to handle CJS imports from ESM.","message":"This library is designed for CommonJS (`require()`) environments and does not natively support ES Modules (`import`). Attempting to use `import` statements will result in runtime errors unless a transpilation step (e.g., Babel or TypeScript) is configured to convert ESM to CJS.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Monitor the GitHub repository's commit history and changelog for any updates before upgrading to newer versions. Thoroughly test your integration after any update.","message":"The package is currently at version 0.3.2, indicating it is pre-1.0. While the README suggests it's 'continuously updated,' pre-1.0 versions may introduce breaking changes between minor or patch releases without strictly adhering to semantic versioning standards.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Ensure `slack.setWebhook('your_webhook_url')` is executed and that 'your_webhook_url' is a properly formatted and valid Slack Incoming Webhook URL.","message":"When using Slack webhooks, the `setWebhook()` method must be called with a valid webhook URL before calling `slack.webhook()`. Failure to do so will result in an error indicating the webhook URL is not set.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `import Slack from 'slack-node';` to `const Slack = require('slack-node');`.","cause":"Attempting to use `import Slack from 'slack-node';` in a Node.js environment that does not transpile ESM to CJS, or forgetting to `require` the library.","error":"ReferenceError: Slack is not defined"},{"fix":"Initialize the `Slack` instance and call `slack.setWebhook('YOUR_SLACK_WEBHOOK_URL')` with a valid URL before sending messages.","cause":"The `setWebhook()` method was not called on the `Slack` instance, or it was called with an invalid/empty URL, before attempting to send a message via `webhook()`.","error":"Error: Webhook URL is not set."},{"fix":"Verify that the API token is correct, active, and has the required scopes for the API methods you are attempting to call (e.g., `users:read` for `users.list`, `chat:write` for `chat.postMessage`).","cause":"The Slack API token provided to the `Slack` constructor or during an API call is invalid, revoked, or lacks the necessary permissions.","error":"Error: Bad token"}],"ecosystem":"npm"}