Skip to content

notchars/stackwatch

Repository files navigation

▲ StackWatch

Smart hot-reload for Discord bots

A better alternative to nodemon with graceful shutdown and beautiful Modern Style logging

npm version npm downloads license


✨ Features

  • 🎨 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

📦 Installation

# npm
npm install -D stackwatch

# pnpm
pnpm add -D stackwatch

# yarn
yarn add -D stackwatch

🚀 Quick Start

npx stackwatch

That's it! StackWatch will watch your index.js and restart on changes.

Output Preview

  ▲ 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

📖 Usage

CLI

# Default usage
npx stackwatch

# Custom script
npx stackwatch -s bot.js

# With verbose logging
npx stackwatch -v

# With Node.js inspector
npx stackwatch --inspect

Programmatic API

const { StackWatch } = require('stackwatch');

const watcher = new StackWatch({
  script: 'bot.js',
  verbose: true,
  delay: 50,
  shutdownTimeout: 3000,
});

watcher.start();

Advanced Configuration

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();

⚙️ CLI Options

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 -

🔧 API Options

interface StackWatchOptions {
  script?: string;
  watch?: string[];
  ignore?: string[];
  delay?: number;
  shutdownTimeout?: number;
  cwd?: string;
  verbose?: boolean;
  beforeRestart?: () => void;
  env?: Record<string, string>;
  nodeArgs?: string[]; 
}

🤖 Example Discord.js Bot

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

📝 Package.json Scripts

{
  "scripts": {
    "dev": "stackwatch",
    "dev:verbose": "stackwatch -v",
    "dev:debug": "stackwatch --inspect"
  }
}

Then run:

npm run dev

🎯 Why StackWatch?

Feature StackWatch Nodemon
Restart Speed 50ms ⚡ 100ms
Shutdown Timeout 3s 5s
Discord.js Optimized
Beautiful Logs ✅ Modern Style ❌ Basic
Graceful Shutdown ✅ Built-in ⚠️ Manual
TypeScript ✅ Full support
Zero Config

🔍 Environment Detection

StackWatch sets STACKWATCH=true in the environment, so you can detect it in your bot:

if (process.env.STACKWATCH) {
  console.log('Running with StackWatch!');
}

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit PRs.

📄 License

MIT © stack


Made with ❤️ by stack

If you like this project, consider giving it a ⭐ on GitHub

About

A better alternative to nodemon with graceful shutdown and beautiful Modern Style logging

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors