
Security News
pnpm 10.16 Adds New Setting for Delayed Dependency Updates
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Lightweight WebSocket client & server wrapper with reconnects, events, acks, and dev tools.
A lightweight JavaScript utility for WebSocket-based client-server communication with:
once
)Initialize a new Node.js project:
npm init -y
npm install socked
Or clone this repo and use the files in src/
.
If installed from npm:
For Node.js (server):
import { createServer } from 'socked';
For Browser (with a bundler):
import { createClient } from 'socked';
If using in the browser without a bundler (via CDN):
<script type="module">
import { createClient } from 'https://cdn.jsdelivr.net/npm/socked/+esm';
// ...your code...
</script>
Create the file: examples/server.js
import { createServer } from '../src/server.js';
const wss = createServer({ port: 3000 });
wss.onClient((client) => {
console.log('Client connected');
client.onEvent('join', (data) => {
console.log('Join:', data);
client.emit('welcome', { message: `Welcome to ${data.room}` });
});
});
Run the server:
node examples/server.js
Create the file: examples/client.html
<!DOCTYPE html>
<html>
<head>
<title>socked Client</title>
</head>
<body>
<h1>socked Client</h1>
<script type="module">
import { createClient } from '../src/client.js';
const socket = createClient('ws://localhost:3000', {
reconnect: true
});
socket.on('connect', () => {
console.log('Connected to server');
socket.emit('join', { room: 'main' });
});
socket.on('welcome', (data) => {
console.log('Server says:', data.message);
document.body.innerHTML += `<p>${data.message}</p>`;
});
socket.on('disconnect', () => {
console.log('Disconnected. Will retry...');
});
</script>
</body>
</html>
Open the file in your browser (e.g., with Live Server in VS Code).
Client:
socket.emitWithAck('saveData', { name: 'Test' })
.then(response => console.log('✅ Ack:', response))
.catch(err => console.error('❌ Timeout or Error:', err));
Server:
client.onEvent('saveData', (data) => {
console.log('Saving data:', data);
client.emit(`saveData_ack_${data._ackId}`, { success: true });
});
socket.once('config', (cfg) => {
console.log('Loaded config:', cfg);
});
Handled internally: the server sends pings and expects pong responses to keep the connection alive.
console.log('Connection Status:', socket.getStatus()); // "connected" or "disconnected"
socket.off('eventName'); // remove all listeners for that event
See src/client.js and src/server.js for full API details.
MIT
Contributions welcome!
Create an issue or open a PR on GitHub.
FAQs
Lightweight WebSocket client & server wrapper with reconnects, events, acks, and dev tools.
We found that socked demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.