A web application and CLI tool for fetching and displaying Nostr events by tag or URI. Built with Preact/HTM for the web interface and Node.js for the CLI.
- Web Interface: Modern, reactive UI built with Preact and HTM
- CLI Tool: Command-line interface for fetching events programmatically
- Real-time: Connects to multiple Nostr relays simultaneously
- URL Parameters: Support for
?uri=
query parameter for direct linking - Flexible: Works with any commitment/tag structure
- Node.js (for CLI tool)
- A web server (for the web interface)
- Clone or download the project files
- Install dependencies for CLI tool:
npm install
-
Start a local web server:
npm run dev # or python3 -m http.server 8000
-
Open your browser to
http://localhost:8000
-
Enter a tag/URI in the input field and click "Fetch Events"
-
You can also use URL parameters:
http://localhost:8000/?uri=your-commitment-uri-here
The CLI tool provides a command-line interface for fetching Nostr events:
# Fetch events by tag
node nostr-cli.js "txo:tbtc4:f0bf1cf69bfd3a7667bf4446683feba06dd6feda098f475e21682cc95f48124a:0"
# Using the --uri flag
node nostr-cli.js --uri "your-commitment-uri"
# Using npm script
npm run cli -- "your-tag-here"
--timeout <ms> Timeout in milliseconds (default: 3000)
--limit <number> Limit number of events (default: 100)
--json Output in JSON format
--relays <urls> Comma-separated relay URLs
# Basic fetch with custom timeout
node nostr-cli.js "my-tag" --timeout 5000
# JSON output for programmatic use
node nostr-cli.js "my-tag" --json
# Custom relays
node nostr-cli.js "my-tag" --relays "wss://relay1.com,wss://relay2.com"
# Combine options
node nostr-cli.js "my-tag" --timeout 10000 --limit 50 --json
index.html
- Web interfacemain.js
- Preact web applicationstyles.css
- Web interface stylesutils.js
- Legacy utility functionsnostr-utils.js
- Shared Nostr client librarynostr-cli.js
- CLI toolpackage.json
- Node.js dependencies and scripts
The NostrClient
class in nostr-utils.js
provides the core functionality:
const { NostrClient } = require('./nostr-utils.js')
const client = new NostrClient([
'wss://relay.damus.io'
// ... custom relays
])
// Fetch events
const events = await client.fetchEvents('tag-value', {
timeout: 3000,
limit: 100
})
// Format for display
const formatted = client.formatEventForDisplay(event)
// Clean up
client.disconnect()
fetchEvents(tagValue, options)
- Fetch events from relaysformatEventForDisplay(event)
- Format event for displayformatEventTime(timestamp)
- Format Unix timestamptruncateEventId(eventId, length)
- Truncate event IDescapeHtml(text)
- Escape HTML charactersdisconnect()
- Close all connections
Default relays used:
- wss://relay.damus.io
- wss://nos.lol
- wss://relay.nostr.band
- wss://nostr-pub.wellorder.net
You can specify custom relays using the --relays
option in the CLI or by passing them to the NostrClient constructor.
npm test
npm run dev
MIT