{"id":12107,"library":"swarm-js","title":"Swarm.js: Decentralized Storage Client","description":"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.","status":"abandoned","version":"0.1.42","language":"javascript","source_language":"en","source_url":"https://github.com/maiavictor/swarm-js","tags":["javascript"],"install":[{"cmd":"npm install swarm-js","lang":"bash","label":"npm"},{"cmd":"yarn add swarm-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add swarm-js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { at } from 'swarm-js';","symbol":"swarm (configured instance)","correct":"const swarm = require(\"swarm-js\").at(\"http://swarm-gateways.net\");"},{"note":"The `upload` function is a method of the `swarm` instance returned by `require('swarm-js').at()`.","wrong":"import { upload } from 'swarm-js';","symbol":"swarm.upload","correct":"swarm.upload(data)"},{"note":"Similarly, `download` is a method of the configured `swarm` instance.","wrong":"import { download } from 'swarm-js';","symbol":"swarm.download","correct":"swarm.download(hash)"},{"note":"The `hash` utility is also a method of the configured `swarm` instance.","wrong":"import { hash } from 'swarm-js';","symbol":"swarm.hash","correct":"swarm.hash(value)"}],"quickstart":{"code":"const swarm = require(\"swarm-js\").at(\"http://swarm-gateways.net\");\n\nconst fileContent = \"Hello Swarm! This is a test file.\";\n\nswarm.upload(fileContent)\n  .then(hash => {\n    console.log(\"Uploaded file. Address:\", hash);\n    return swarm.download(hash);\n  })\n  .then(downloadedArray => {\n    console.log(\"Downloaded file content:\", swarm.toString(downloadedArray));\n  })\n  .catch(error => {\n    console.error(\"An error occurred:\", error);\n  });\n\nconst dir = {\n  \"/hello.txt\": { type: \"text/plain\", data: \"Hello from directory!\" },\n  \"/meta.json\": { type: \"application/json\", data: JSON.stringify({ version: \"1.0\" }) }\n};\n\nswarm.upload(dir)\n  .then(dirHash => {\n    console.log(\"Uploaded directory. Address:\", dirHash);\n    return swarm.download(dirHash);\n  })\n  .then(downloadedDir => {\n    console.log(\"Downloaded directory:\");\n    for (let path in downloadedDir) {\n      console.log(`- ${path}: ${downloadedDir[path].data.toString()}`);\n    }\n  })\n  .catch(error => {\n    console.error(\"Directory operation failed:\", error);\n  });","lang":"javascript","description":"Demonstrates installation, configuration with a gateway, and basic upload/download operations for both single files and directories."},"warnings":[{"fix":"Migrate to an actively maintained alternative for Swarm interactions, such as Erebos (https://erebos.js.org/).","message":"This 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.","severity":"breaking","affected_versions":">=0.1.42"},{"fix":"Use with extreme caution and be aware of potential issues; strongly consider actively maintained alternative libraries for any new or critical projects.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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');`","cause":"Attempting to import `at` as a named export (`import { at } from 'swarm-js';`) or incorrectly calling `require('swarm-js')` without chaining `.at()` immediately.","error":"TypeError: swarm.at is not a function"},{"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.","cause":"Attempting to use `require()` in an ES Module context, or using `import` syntax directly with this CommonJS-only library without proper transpilation.","error":"ERR_REQUIRE_ESM"},{"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.","cause":"The Swarm gateway specified in `.at()` is unreachable, offline, or refusing connections from your environment.","error":"Error: connect ECONNREFUSED"}],"ecosystem":"npm"}