npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@blockcore/ws

v0.0.1

Published

Blockcore-ws is a WebSocket library designed to facilitate seamless WebSocket communication across various environments.

Readme

Blockcore WebSocket (blockcore-ws) 🌐

Blockcore WebSocket (blockcore-ws) is a WebSocket library designed to provide an easy and seamless way to implement WebSocket communication in various environments. It supports both Node.js and browser environments, making it versatile for different use cases.

Features ✨

  • 🚀 Easy to use API
  • 🌍 Supports both Node.js and browser environments
  • 💡 Lightweight and efficient

Installation 📦

To install the blockcore-ws library, use the following npm command:

npm install @blockcore/ws

Usage 🚀

Node.js Example 🖥️

Here is an example of how to use blockcore-ws in a Node.js environment:

  1. Create a file named app.js and add the following code:

    import WebSocket from '@blockcore/ws';
    
    const ws = new WebSocket('wss://echo.websocket.org');
    
    ws.on('open', function open() {
      console.log('connected');
      ws.send(Date.now());
    });
    
    ws.on('close', function close() {
      console.log('disconnected');
    });
    
    ws.on('message', function incoming(data) {
      console.log(`Roundtrip time: ${Date.now() - data} ms`);
      ws.send(Date.now());
    });
  2. Ensure your package.json includes "type": "module" to use ES modules:

    {
      "name": "your-project-name",
      "version": "1.0.0",
      "description": "",
      "main": "app.js",
      "type": "module",
      "scripts": {
        "start": "node app.js"
      },
      "dependencies": {
        "@blockcore/ws": "^0.0.1"
      }
    }
  3. Install dependencies and run the example:

    npm install
    npm start

Browser Example 🌐

To use blockcore-ws in a browser environment, follow these steps:

  1. Create an HTML file, index.html, and include a script to run the WebSocket code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Blockcore WebSocket Example</title>
    </head>
    <body>
        <script type="module">
            import WebSocket from './path/to/blockcore-ws/browser.js';
    
            const ws = new WebSocket('wss://echo.websocket.org');
    
            ws.onopen = () => {
                console.log('connected');
                ws.send(Date.now());
            };
    
            ws.onclose = () => {
                console.log('disconnected');
            };
    
            ws.onmessage = (event) => {
                console.log(`Roundtrip time: ${Date.now() - event.data} ms`);
                ws.send(Date.now());
            };
        </script>
    </body>
    </html>
  2. Serve the HTML file using a local server. You can use http-server or any other local server tool:

    npm install -g http-server
    http-server
  3. Open the served HTML file in your browser to see the WebSocket in action.

Running Examples 🛠️

Webpack Example 📦

The blockcore-ws library includes a Webpack example to demonstrate how to bundle and use the library with Webpack.

  1. Navigate to the example directory:

    cd path/to/blockcore-ws/example/webpack
  2. Ensure your webpack.config.js is set up to use ES modules:

    import path from 'path';
    
    export default {
      context: path.resolve(),
      entry: {
        app: path.join(path.resolve(), './app.js')
      },
      target: 'web',
      output: {
        path: path.resolve(),
        filename: '[name].output.js',
      }
    };
  3. Install dependencies and build the project:

    npm install
    npm run build
  4. Serve the output file using a local server and open it in a browser:

    http-server

With these instructions, you should be able to install, run, and use the blockcore-ws library effectively in both Node.js and browser environments. Happy coding! 🎉