Search code examples
node.jsipfs

How to run the IPFS example below in node?


See https://proto.school/#/mutable-file-system/02

there is some example with no context. You can run it in the browser they have set up fine but there is no context given about how to paste that into the node REPL.

What do you paste into the node REPL to make this work? How to redefine the function once it has been defined.

All tutorials should be REPL/CLI based.


Solution

  • The following code snippet will run in the node REPL:

    const IPFS = require('ipfs')
    
    async function run() {
        const ipfs = await IPFS.create()
    
        console.log(await ipfs.files.stat('/'))
    }
    
    run()
    

    Which will print the result from ipfs.files.stat('/').

    At ProtoSchool we create the ipfs node instance behind the scenes, which is available in the global variable ipfs.

    You can check more examples from js-ipfs docs here.

    You can also share feedback or report issues related to ProtoSchool in our github issues tracker.