Registry / http-networking / swarm-js

swarm-js

JSON →
library0.1.42jsnpmunverified

Swarm.js is a JavaScript library designed to facilitate interaction with the Swarm network, a decentralized storage platform. The package provides functionalities for uploading and downloading files and directories to and from Swarm, as well as hashing various data types. It specifically targets both Node.js and browser environments for these operations. The current stable version appears to be 0.1.42, indicating it never reached a 1.0 release. The library's development has ceased, with the maintainer explicitly stating it is no longer actively maintained and recommending Erebos (https://erebos.js.org/) as an alternative. Therefore, users should be aware of its abandoned status and consider alternatives for new projects, or for maintaining existing ones.

npm install swarm-js
INSTALL
IMPORT
SIG · SWARM-JS
S
swarm-js
http-networkingjavascriptv0.1.42
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

swarm (configured instance)
const swarm = require("swarm-js").at("http://swarm-gateways.net");
import { at } from 'swarm-js';
The library primarily uses CommonJS `require()` syntax. The main export is a function that returns the Swarm API instance when called with a gateway URL.
swarm.upload
swarm.upload(data)
import { upload } from 'swarm-js';
The `upload` function is a method of the `swarm` instance returned by `require('swarm-js').at()`.
swarm.download
swarm.download(hash)
import { download } from 'swarm-js';
Similarly, `download` is a method of the configured `swarm` instance.
swarm.hash
swarm.hash(value)
import { hash } from 'swarm-js';
The `hash` utility is also a method of the configured `swarm` instance.

Demonstrates installation, configuration with a gateway, and basic upload/download operations for both single files and directories.

const swarm = require("swarm-js").at("http://swarm-gateways.net"); const fileContent = "Hello Swarm! This is a test file."; swarm.upload(fileContent) .then(hash => { console.log("Uploaded file. Address:", hash); return swarm.download(hash); }) .then(downloadedArray => { console.log("Downloaded file content:", swarm.toString(downloadedArray)); }) .catch(error => { console.error("An error occurred:", error); }); const dir = { "/hello.txt": { type: "text/plain", data: "Hello from directory!" }, "/meta.json": { type: "application/json", data: JSON.stringify({ version: "1.0" }) } }; swarm.upload(dir) .then(dirHash => { console.log("Uploaded directory. Address:", dirHash); return swarm.download(dirHash); }) .then(downloadedDir => { console.log("Downloaded directory:"); for (let path in downloadedDir) { console.log(`- ${path}: ${downloadedDir[path].data.toString()}`); } }) .catch(error => { console.error("Directory operation failed:", error); });
Debug
Known issues
breakingThis library is explicitly unmaintained and abandoned by its creator. No further updates, bug fixes, or security patches will be released, making it unsuitable for production use.
fix
Migrate to an actively maintained alternative for Swarm interactions, such as Erebos (https://erebos.js.org/).
affects: >=0.1.42
gotchaThe package is still in a pre-1.0 version (0.1.42), indicating it was never considered stable by its original maintainer. This implies potential API instability, incomplete features, and lack of long-term support.
fix
Use with extreme caution and be aware of potential issues; strongly consider actively maintained alternative libraries for any new or critical projects.
affects: >=0.1.0
gotchaThe primary usage pattern shown is CommonJS (`require`). Modern Node.js and browser environments typically prefer ES Modules (`import`). Direct ESM compatibility is not guaranteed without bundling or transpilation, and using `import` directly may lead to errors.
fix
For Node.js, ensure your project is configured for CommonJS or use a bundler (e.g., Webpack, Rollup) for browser environments if you need ESM context. Always use `require()` as shown in the documentation.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: swarm.at is not a function
Attempting to import `at` as a named export (`import { at } from 'swarm-js';`) or incorrectly calling `require('swarm-js')` without chaining `.at()` immediately.
fix
Ensure you are using the CommonJS `require` syntax and calling the `.at()` method immediately: `const swarm = require('swarm-js').at('http://swarm-gateways.net');`
ERR_REQUIRE_ESM
Attempting to use `require()` in an ES Module context, or using `import` syntax directly with this CommonJS-only library without proper transpilation.
fix
Change `import` statements to `const swarm = require('swarm-js').at(...)` or configure your build process to transpile CommonJS modules for ESM consumption in an `ESM` project. If in an ES Module environment, you might need a wrapper or dynamic import if `require` is not available.
Error: connect ECONNREFUSED
The Swarm gateway specified in `.at()` is unreachable, offline, or refusing connections from your environment.
fix
Verify the Swarm gateway URL is correct and the gateway is operational and accessible from your network. Try a different public gateway URL if available, or ensure your firewall/network settings allow the connection.
Upgrade
Version history
0.1.42latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
swarm-js — npm install swarm-js · libregistry