Explore the docs
·
Report Bug
·
Request Feature/Example
- Table of Contents
- About The Project
- Getting Started
- Usage
- Documentation
- Contributing
- Want to hack on IPFS?
- Read the docs
- Look into other examples to learn how to spawn a Helia node in Node.js and in the Browser
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
- Check out https://docs.ipfs.io for tips, how-tos and more
- See https://blog.ipfs.io for news and more
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- Node.js - Download & Install Node.js and the npm package manager.
> npm install
> npm start
ts-node is a TypeScript execution and REPL tool for running TypeScript files from the command line, similar to how you would run JavaScript files with node.js.
It gives the illusion of compilation-free code execution by using JIT compilation to turn your TypeScript code into JavaScript at runtime and is a useful development tool.
Because TypeScript outputs CommonJS by default, and Helia is written using more modern ECMAScript Modules it's necessary to override the default configuration ts-node
uses.
This is the minimum config that is required.
The target to ES2021
- this will ensure ESM is output and not CJS.
module should be set to at least ES2022
- this is necessary to support things like private class fields.
moduleResolution should be set to node
or node16
to enable use of import
as well as require
.
We have to tell node that this is an ESM project.
The type
field in your package.json
should be set to module
. This means the .js
extension is interpreted as ESM by default.
It also means that import paths within your own project need file extensions, so any import foo from './bar/baz'
will need to be changed to import foo from './bar/baz.js'
.
TypeScript will not add this for you.
⚠️ Currently ts-node is broken on Node.js v20 so the instructions below will not work until the issue is fixed.The workaround is to pass
ts-node/esm
as a loader:$ node --loader ts-node/esm ./src/index.ts
Alternatively consider using TypeScript Execute which works in a similar way but does not have the same problem.
ts-node
has an --esm
flag that is slightly counter-intuitively necessary to enable loading .ts
files for JIT compilation via import
:
% npx ts-node --help | grep esm
--esm Bootstrap with the ESM loader, enabling full ESM support
It is necessary to pass this flag when running ts-node
tsconfig.json
{
"compilerOptions": {
"module": "ES2022",
"target": "ES2021",
"moduleResolution": "node"
},
// other settings here
}
package.json
{
"type": "module",
// other settings here
}
You can now run ts code using ts-node:
⚠️ As of Node.js v20 the following command will not work, please see the note above.
> npx ts-node --esm ./src/index.ts
Helia is running
PeerId: 12D3KooWMUv1MYSYrgsEg3ykfZ6nDZwaT72LtVCheRNhH15kzroz
That's it! You just ran an ESM-only module using ts-node with JIT compilation!
For more examples, please refer to the Documentation
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the IPFS Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -a -m 'feat: add some amazing feature'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:
Read the Code of Conduct and JavaScript Contributing Guidelines.
- Check out existing issues The issue list has many that are marked as 'help wanted' or 'difficulty:easy' which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
- Look at the Helia Roadmap This are the high priority items being worked on right now
- Perform code reviews More eyes will help a. speed the project along b. ensure quality, and c. reduce possible future bugs
- Add tests. There can never be enough tests