Smart hot-reload for Discord bots
A better alternative to nodemon with graceful shutdown and beautiful Modern Style logging
- 🎨 Beautiful Logs - Modern Style terminal output
- ⚡ Lightning Fast - 50ms restart delay (2x faster than nodemon)
- 🔄 Graceful Shutdown - Properly closes Discord connections
- 🎯 Smart Watching - Auto-ignores node_modules, dist, .git
- 💪 Error Resilient - Won't crash when your bot has errors
- 📦 TypeScript Ready - Full TypeScript support out of the box
- 🔧 Zero Config - Works immediately with sensible defaults
# npm
npm install -D stackwatch
# pnpm
pnpm add -D stackwatch
# yarn
yarn add -D stackwatchnpx stackwatchThat's it! StackWatch will watch your index.js and restart on changes.
▲ StackWatch v0.0.1
Made by stack (silencestack)
○ info - watching index.js for changes
◼ ready - bot started successfully
○ info - restarting due to changes...
◼ ready - bot started successfully
# Default usage
npx stackwatch
# Custom script
npx stackwatch -s bot.js
# With verbose logging
npx stackwatch -v
# With Node.js inspector
npx stackwatch --inspectconst { StackWatch } = require('stackwatch');
const watcher = new StackWatch({
script: 'bot.js',
verbose: true,
delay: 50,
shutdownTimeout: 3000,
});
watcher.start();const { StackWatch } = require('stackwatch');
const watcher = new StackWatch({
script: 'bot.js',
watch: ['**/*.js', '**/*.json', 'commands/**'],
ignore: ['node_modules/**', 'temp/**'],
delay: 100,
shutdownTimeout: 5000,
verbose: true,
beforeRestart: async () => {
console.log('Running build...');
// Your custom logic here
},
env: {
NODE_ENV: 'development',
},
nodeArgs: ['--inspect'],
});
watcher.start();| Option | Description | Default |
|---|---|---|
-s, --script <file> |
Entry file | index.js |
-d, --delay <ms> |
Restart delay | 50ms |
-t, --timeout <ms> |
Shutdown timeout | 3000ms |
-v, --verbose |
Verbose logging | false |
--inspect |
Enable Node.js inspector | - |
--inspect-brk |
Enable inspector with breakpoint | - |
-h, --help |
Show help | - |
interface StackWatchOptions {
script?: string;
watch?: string[];
ignore?: string[];
delay?: number;
shutdownTimeout?: number;
cwd?: string;
verbose?: boolean;
beforeRestart?: () => void;
env?: Record<string, string>;
nodeArgs?: string[];
}const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', (message) => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
process.on('SIGTERM', async () => {
console.log('Shutting down gracefully...');
await client.destroy();
process.exit(0);
});
client.login(process.env.DISCORD_TOKEN);Run with:
npx stackwatch{
"scripts": {
"dev": "stackwatch",
"dev:verbose": "stackwatch -v",
"dev:debug": "stackwatch --inspect"
}
}Then run:
npm run dev| Feature | StackWatch | Nodemon |
|---|---|---|
| Restart Speed | 50ms ⚡ | 100ms |
| Shutdown Timeout | 3s | 5s |
| Discord.js Optimized | ✅ | ❌ |
| Beautiful Logs | ✅ Modern Style | ❌ Basic |
| Graceful Shutdown | ✅ Built-in | |
| TypeScript | ✅ Full support | ✅ |
| Zero Config | ✅ | ✅ |
StackWatch sets STACKWATCH=true in the environment, so you can detect it in your bot:
if (process.env.STACKWATCH) {
console.log('Running with StackWatch!');
}Contributions are welcome! Feel free to open issues or submit PRs.
MIT © stack
Made with ❤️ by stack
If you like this project, consider giving it a ⭐ on GitHub