Now we’ll create the Node project, drop in the bot code, and run it on your machine.
1. Create the project
-
Create a new folder for your project and open it in VS Code.
-
Open the integrated terminal with Terminal → New Terminal so commands run inside the project folder.
-
Initialize the project and install dependencies:
npm init -y
npm install @slack/bolt dotenv
2. Store your tokens in .env
Create a .env file in the project folder and paste your two tokens:
SLACK_BOT_TOKEN=xoxb-... # Bot User OAuth Token (from OAuth & Permissions)
SLACK_APP_TOKEN=xapp-... # App-Level Token (from Basic Information → App-Level Tokens)
Then create a .gitignore so .env never gets committed:
node_modules
.env
3. Write the bot
Create index.js in the project folder and paste this:
require("dotenv").config();
const { App } = require("@slack/bolt");
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true
});
app.command("/dsb-ping", async ({ command, ack, respond }) => {
const start = Date.now();
await ack();
const latency = Date.now() - start;
await respond({ text: `Pong!\nLatency: ${latency}ms` });
});
(async () => {
await app.start();
console.log("bot is running!");
})();
4. Run the bot
node index.js
If it works, you’ll see:
bot is running!
Test your slash command in Slack — type /dsb-ping in any channel. The bot should reply with the latency.

How the command code works
app.command("/command-name", async ({ ack, respond }) => {
// your code here
});
| Part |
What it does |
app.command() |
Registers a slash command |
"/command-name" |
The command Slack listens for |
async |
Allows asynchronous operations like API calls |
ack() |
Acknowledges the command to Slack |
respond() |
Sends a message back to Slack |