1.0.0 • Published 4 months ago

sockster v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

🔌 sockster

A lightweight, blazing-fast WebSocket server that broadcasts all events to connected clients. Perfect for real-time applications, chat systems, or any project requiring WebSocket functionality.

npm version Docker Pulls License: MIT

✨ Features

  • 🎯 Simple to use - Just start the server and it broadcasts all events
  • 🔄 Universal Broadcasting - Every event is automatically broadcast to all connected clients
  • 🛡️ Production Ready - Built-in CORS, error handling, and health checks
  • 🐳 Docker Support - Ready-to-use Docker images with environment variable support
  • 📦 Easy Deployment - Deploy anywhere with comprehensive environment variable support
  • 🔌 Socket.IO Powered - Built on the reliable Socket.IO framework

🚀 Quick Start

NPM

# Install the package
npm install sockster

# Create an .env file
echo "SOCKSTER_PORT=4000\nSOCKSTER_ORIGIN_URL=http://localhost:3000" > .env

# Start the server
npx sockster

Docker

# Pull and run
docker run -p 4000:4000 -e SOCKSTER_ORIGIN_URL=http://localhost:3000 djurnamn/sockster

Docker Compose

services:
  sockster:
    image: djurnamn/sockster:latest
    ports:
      - "${SOCKSTER_PORT:-4000}:4000"
    environment:
      - SOCKSTER_PORT=4000
      - SOCKSTER_ORIGIN_URL=http://localhost:3000

🔌 Client Connection

Connect from your frontend application (JavaScript/TypeScript):

import { io } from "socket.io-client";

const socket = io("http://localhost:4000");

// Listen for connection
socket.on("connect", () => {
  console.log("Connected to sockster! 🎉");
});

// Send an event
socket.emit("my-event", { data: "Hello!" });

// Listen for events
socket.on("my-event", (data) => {
  console.log("Received:", data);
});

🌍 Production Deployment

Railway (Recommended)

  1. Install Railway CLI:

    npm i -g @railway/cli
  2. Deploy to Railway:

    railway login
    railway init
    railway up
  3. Set environment variables:

    railway variables add SOCKSTER_ORIGIN_URL=https://your-frontend-app.com
  4. Get your WebSocket URL:

    railway domain
  5. Update your client configuration:

    const socket = io("wss://your-app-name.railway.app");

⚙️ Environment Variables

VariableDescriptionDefault
SOCKSTER_PORTPort to run the server on4000
SOCKSTER_ORIGIN_URLAllowed CORS origin-

🛠️ Development

# Clone the repository
git clone https://github.com/djurnamn/sockster.git

# Install dependencies
pnpm install

# Start the server
pnpm start

🤝 Contributing

Contributions are welcome! Feel free to:

  • 🐛 Report bugs
  • 💡 Suggest features
  • 🔧 Submit pull requests

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

Built with:

  • Socket.IO - Reliable real-time framework
  • dotenv - Environment variable management

🌟 Star Us!

If you find sockster helpful, please consider giving it a star ⭐️ It helps others discover the project!