{"id":18584450,"url":"https://github.com/ipfs-examples/js-ipfs-101","last_synced_at":"2025-05-16T05:33:11.804Z","repository":{"id":104999278,"uuid":"376834342","full_name":"ipfs-examples/js-ipfs-101","owner":"ipfs-examples","description":"Example of JS-IPFS implementation following the tutorial 101","archived":false,"fork":false,"pushed_at":"2025-05-01T07:36:24.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-01T08:30:25.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipfs-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-14T13:33:39.000Z","updated_at":"2025-05-01T07:36:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"77bcc358-3c16-40be-892e-1b2461a7669c","html_url":"https://github.com/ipfs-examples/js-ipfs-101","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"ipfs-examples/example-fork-go-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-101","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-101/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-101/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-101/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs-examples","download_url":"https://codeload.github.com/ipfs-examples/js-ipfs-101/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254473844,"owners_count":22077185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T00:27:34.082Z","updated_at":"2025-05-16T05:33:11.785Z","avatar_url":"https://github.com/ipfs-examples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://js.ipfs.io\" title=\"JS IPFS\"\u003e\n    \u003cimg src=\"https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png\" alt=\"IPFS in JavaScript logo\" width=\"244\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003e\u003cb\u003eTutorial 101\u003c/b\u003e\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003e\u003ci\u003eDemo of \"Using go-ipfs as a library\" with js-ipfs\u003c/i\u003e\u003c/b\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png\" width=\"200\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/ipfs/js-ipfs/tree/master/docs\"\u003eExplore the docs\u003c/a\u003e\n  ·\n  \u003ca href=\"https://codesandbox.io/\"\u003eView Demo\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/ipfs-examples/js-ipfs-examples/issues\"\u003eReport Bug\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/ipfs-examples/js-ipfs-examples/issues\"\u003eRequest Feature/Example\u003c/a\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Table of Contents](#table-of-contents)\n- [About The Project](#about-the-project)\n- [Getting Started](#getting-started)\n  - [Prerequisites](#prerequisites)\n  - [Installation and Running example](#installation-and-running-example)\n- [Usage](#usage)\n  - [Code analysis](#code-analysis)\n- [References](#references)\n- [Documentation](#documentation)\n- [Contributing](#contributing)\n- [Want to hack on IPFS?](#want-to-hack-on-ipfs)\n\n## About The Project\n\n- Read the [docs](https://github.com/ipfs/js-ipfs/tree/master/docs)\n- Look into other [examples](https://github.com/ipfs-examples/js-ipfs-examples) to learn how to spawn an IPFS node in Node.js and in the Browser\n- Consult the [Core API docs](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api) to see what you can do with an IPFS node\n- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it\n- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs\n- Check out https://docs.ipfs.io for tips, how-tos and more\n- See https://blog.ipfs.io for news and more\n- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io\n\n## Getting Started\n\n### Prerequisites\n\nMake sure you have installed all of the following prerequisites on your development machine:\n\n- Git - [Download \u0026 Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.\n- Node.js - [Download \u0026 Install Node.js](https://nodejs.org/en/download/) and the npm package manager.\n\n### Installation and Running example\n\n```console\n\u003e npm install\n\u003e npm start\n```\n\n## Usage\n\nThis tutorial is the sibling of the [go-ipfs \"Using go-ipfs as a library\" tutorial](https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library).\n\nIn this tutorial, we go through spawning an IPFS node, adding a file and cat'ing the file multihash locally and through the gateway.\n\nYou can find a complete version of this tutorial in [1.js](./1.js). For this tutorial, you need to install `ipfs` using `npm install ipfs`.\n\n### Code analysis\n\nCreating an IPFS instance can be done in one line, after requiring the module, you simply have to:\n\n```js\nimport * as IPFS from 'ipfs-core';\n\nasync function main() {\n  const node = await IPFS.create();\n  // ...\n}\n\nmain();\n```\n\nAs a test, we are going to check the version of the node.\n\n```js\nimport * as IPFS from 'ipfs-core';\n\nasync function main() {\n  const node = await IPFS.create();\n  const version = await node.version();\n\n  console.log(\"Version:\", version.version);\n  // ...\n}\n\nmain();\n```\n\n(If you prefer not to use `async`/`await`, you can instead use `.then()` as you would with any promise, or pass an [error-first callback](https://nodejs.org/api/errors.html#errors_error_first_callbacks), e.g. `node.version((err, version) =\u003e { ... })`)\n\nRunning the code above gets you:\n\n```bash\n\u003e node 1.js\nVersion: 0.31.2\n```\n\nNow let's make it more interesting and add a file to IPFS using `node.add`. A file consists of a path and content.\n\nYou can learn about the IPFS File API at [interface-ipfs-core](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md).\n\n```js\nimport * as IPFS from 'ipfs-core';\n\nasync function main() {\n  const node = await IPFS.create();\n  const version = await node.version();\n\n  console.log(\"Version:\", version.version);\n\n  const fileAdded = await node.add({\n    path: \"hello.txt\",\n    content: \"Hello World 101\",\n  });\n\n  console.log(\"Added file:\", fileAdded.path, fileAdded.cid);\n  // ...\n}\n\nmain();\n```\n\nYou can now go to an IPFS Gateway and load the printed hash from a gateway. Go ahead and try it!\n\n```bash\n\u003e node 1.js\nVersion: 0.31.2\n\nAdded file: hello.txt QmXgZAUWd8yo4tvjBETqzUy3wLx5YRzuDwUQnBwRGrAmAo\n# Copy that hash and load it on the gateway, here is a prefiled url:\n# https://ipfs.io/ipfs/QmXgZAUWd8yo4tvjBETqzUy3wLx5YRzuDwUQnBwRGrAmAo\n```\n\nThe last step of this tutorial is retrieving the file back using the `cat` 😺 call.\n\n```js\nimport * as IPFS from 'ipfs-core';\n\nasync function main() {\n  const node = await IPFS.create();\n  const version = await node.version();\n\n  console.log(\"Version:\", version.version);\n\n  const fileAdded = await node.add({\n    path: \"hello.txt\",\n    content: \"Hello World 101\",\n  });\n\n  console.log(\"Added file:\", fileAdded.path, fileAdded.cid);\n\n  const decoder = new TextDecoder()\n  let text = ''\n\n  for await (const chunk of node.cat(fileAdded.cid)) {\n    text += decoder.decode(chunk, {\n      stream: true\n    })\n  }\n\n  console.log(\"Added file contents:\", text);\n}\n\nmain();\n```\n\nThat's it! You just added and retrieved a file from the Distributed Web!\n\n_For more examples, please refer to the [Documentation](#documentation)_\n\n## References\n\n- Documentation:\n  - [IPFS CONFIG](https://github.com/ipfs/js-ipfs/blob/master/docs/CONFIG.md)\n  - [MISCELLANEOUS](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/MISCELLANEOUS.md)\n  - [FILES](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md)\n- Tutorials:\n  - [MFS API](https://proto.school/mutable-file-system)\n  - [Regular File API](https://proto.school/regular-files-api)\n\n## Documentation\n\n- [Config](https://docs.ipfs.io/)\n- [Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api)\n- [Examples](https://github.com/ipfs-examples/js-ipfs-examples)\n- [Development](https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md)\n- [Tutorials](https://proto.school)\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the IPFS Project\n2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)\n3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`)\n4. Push to the Branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Want to hack on IPFS?\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\nThe IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:\n\nRead the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md).\n\n- **Check out existing issues** The [issue list](https://github.com/ipfs/js-ipfs/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge\n- **Look at the [IPFS Roadmap](https://github.com/ipfs/roadmap)** This are the high priority items being worked on right now\n- **Perform code reviews** More eyes will help\n  a. speed the project along\n  b. ensure quality, and\n  c. reduce possible future bugs.\n- **Add tests**. There can never be enough tests.\n- **Join the [Weekly Core Implementations Call](https://github.com/ipfs/team-mgmt/issues/992)** it's where everyone discusses what's going on with IPFS and what's next\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-examples%2Fjs-ipfs-101","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs-examples%2Fjs-ipfs-101","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-examples%2Fjs-ipfs-101/lists"}