
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@nostr-connect/nostr-reqres
Advanced tools
A JavaScript library for managing request/response communication over Nostr protocol
The NostrReqRes library is a JavaScript library that provides an easy way to create, manage, and track request/response communication of any size over Nostr protocol. By automatically splitting and reassembling large payloads into smaller chunks, it allows seamless handling of requests and responses without size limitations. The library utilizes Nostr Tools for low-level operations and implements higher-level abstractions for request and response handling.
npm install @nostr-connect/nostr-reqres
// Import the NostrReqRes module
import { NostrReqRes } from "@nostr-connect/nostr-reqres"
// Define an immediately invoked async function expression (IIFE)
void (async () => {
// Create new instances of NostrReqRes for the sender and the receiver
const nostrReqResSENDER = new NostrReqRes()
const nostrReqResRECEIVER = new NostrReqRes()
// Connect both sender and receiver to the WebSocket server at localhost:7001
await Promise.all([
nostrReqResSENDER.connect("ws://localhost:7001"),
nostrReqResRECEIVER.connect("ws://localhost:7001")
])
// Set up an event listener for incoming requests on the receiver
nostrReqResRECEIVER.onReqReceived(async (req) => {
// Log the request data to the console
console.log(req.data) // ping
// Send a response with the data "pong" back to the sender
await req.sendRes({
data: "pong"
})
})
// Send a request from the sender to the receiver with the data "ping"
const res = await nostrReqResSENDER.sendReq({
receiver: nostrReqResRECEIVER.pubkey,
data: "ping"
})
// Log the response data to the console
console.log(res.data) // pong
})()
// Catch any errors and log them to the console
.catch((err) => {
console.error(err)
})
// Import the NostrReqRes library
import { NostrReqRes } from "@nostr-connect/nostr-reqres";
// Create an immediately invoked async function expression
void (async () => {
// Initialize sender and receiver instances of NostrReqRes
const nostrReqResSENDER = new NostrReqRes();
const nostrReqResRECEIVER = new NostrReqRes();
// Connect both sender and receiver to the WebSocket server at localhost on port 7001
await Promise.all([
nostrReqResSENDER.connect("ws://localhost:7001"),
nostrReqResRECEIVER.connect("ws://localhost:7001")
]);
// Set up an event listener for when the receiver receives a request chunk
nostrReqResRECEIVER.onReq(async (req) => {
// Log received request chunks
req.onChunk((chunk) => {
console.log("req chunk received", chunk);
});
// Set up an event listener for when the entire request is received
req.onReceived(async (req) => {
// Log the received request data
console.log(req.data); // "ping"
// Create a response object with the data "pong"
const res = req.createRes({
data: "pong"
});
// Send the response back to the sender
await res.send();
});
});
// Create a new request object with the receiver's public key and the data "ping"
const req = await nostrReqResSENDER.createReq({
receiver: nostrReqResRECEIVER.pubkey,
data: "ping"
});
// Log sent request chunks
req.onChunk((chunk) => {
console.log("req chunk sent", chunk);
});
// Send the request and wait for the response
const res = await req.send();
// Log the received response data
console.log(res.data); // "pong"
})()
.catch((err) => {
// Log any errors that occur during execution
console.error(err);
});
kind (optional, number): The kind of event to be used for request-response communication. Default is 28080.maxBytesPerChunk (optional, number): The maximum number of bytes allowed per chunk when splitting large payloads. Default is NostrReqRes.MAX_BYTES_PER_CHUNK (16384).secretKey (optional, string): The secret key to be used for signing and encrypting events. Default is a randomly generated private key.validateEventsSig (optional, boolean): A flag indicating whether to validate event signatures when receivd; this shuold be done by the relay. Default is false.waitForRealyAckWhenSendingChunks (optional, boolean): A flag indicating whether to wait for a relay acknowledgement when sending chunks; not all the relay implements the ack on ephimeral kinds. Default is false.example:
import { NostrReqRes } from "@nostr-connect/nostr-reqres";
const nostrReqRes = new NostrReqRes({
kind: 28080,
maxBytesPerChunk: 1000,
secretKey: "your_secret_key",
validateEventsSig: false,
waitForRealyAckWhenSendingChunks: true
});
FAQs
A JavaScript library for managing request/response communication over Nostr protocol
We found that @nostr-connect/nostr-reqres demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.