Registry / communication / slack-node

slack-node

JSON →
library0.3.2jsnpmunverified

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.

npm install slack-node
INSTALL
IMPORT
SIG · SLACK-NODE
S
slack-node
communicationjavascriptv0.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Slack
const Slack = require('slack-node');
import Slack from 'slack-node';
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.
Slack instance (webhook)
const slack = new Slack(); slack.setWebhook('__your_webhook_url__');
For webhook usage, an instance is created without an API token, and the webhook URL must be explicitly set via `setWebhook()`.
Slack instance (API)
const slack = new Slack('__your_api_token__');
For Slack Web API calls, the API token should be passed directly to the constructor when creating the `Slack` instance.

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.

const Slack = require('slack-node'); async function main() { // Webhook usage const webhookUrl = process.env.SLACK_WEBHOOK_URL ?? '__your_webhook_url__'; const slackWebhook = new Slack(); slackWebhook.setWebhook(webhookUrl); if (webhookUrl === '__your_webhook_url__') { console.warn("Please provide a valid SLACK_WEBHOOK_URL environment variable or replace the placeholder."); } else { try { const webhookResponse = await slackWebhook.webhook({ channel: "#general", username: "webhookbot", text: "Hello from async/await via webhook!", icon_emoji: ":ghost:" }); console.log("Webhook message sent:", webhookResponse.data); } catch (err) { console.error("Webhook error:", err); } } // API usage const apiToken = process.env.SLACK_API_TOKEN ?? '__your_api_token__'; if (apiToken === '__your_api_token__') { console.warn("Please provide a valid SLACK_API_TOKEN environment variable or replace the placeholder."); } else { const slackApi = new Slack(apiToken); try { const usersList = await slackApi.api("users.list"); console.log("Users list:", usersList.members.map(u => u.real_name)); const chatPostMessage = await slackApi.api("chat.postMessage", { text: "hello from async/await via API", channel: "#general" }); console.log("API message sent (timestamp):", chatPostMessage.ts); } catch (err) { console.error("API error:", err); } } } main();
Debug
Known issues
gotchaThis 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.
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.
affects: >=0.1.0
gotchaThe 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.
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.
affects: <1.0.0
gotchaWhen 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.
fix
Ensure `slack.setWebhook('your_webhook_url')` is executed and that 'your_webhook_url' is a properly formatted and valid Slack Incoming Webhook URL.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: Slack is not defined
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.
fix
Change `import Slack from 'slack-node';` to `const Slack = require('slack-node');`.
Error: Webhook URL is not set.
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()`.
fix
Initialize the `Slack` instance and call `slack.setWebhook('YOUR_SLACK_WEBHOOK_URL')` with a valid URL before sending messages.
Error: Bad token
The Slack API token provided to the `Slack` constructor or during an API call is invalid, revoked, or lacks the necessary permissions.
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`).
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
slack-node — npm install slack-node · libregistry