Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

TypeError: node.add is not a function #1783

Closed
birbird opened this issue Dec 17, 2018 · 2 comments
Closed

TypeError: node.add is not a function #1783

birbird opened this issue Dec 17, 2018 · 2 comments

Comments

@birbird
Copy link

birbird commented Dec 17, 2018

Simplely run this example https://github.com/ipfs/js-ipfs/tree/master/examples/ipfs-101

My index.js is

const IPFS = require('ipfs')

const node = new IPFS()

node.on('ready', async () => {
  const version = await node.version()

  console.log('Version:', version.version)

  const filesAdded = await node.add({
    path: 'hello.txt',
    content: Buffer.from('Hello World 101')
  })

  console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)
})

The output is

Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmdtGx5n4CgWa3hNRJUTajHVSmoSPD1buNK9AYK1XYPofq
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmdtGx5n4CgWa3hNRJUTajHVSmoSPD1buNK9AYK1XYPofq
Swarm listening on /ip4/192.168.1.20/tcp/4002/ipfs/QmdtGx5n4CgWa3hNRJUTajHVSmoSPD1buNK9AYK1XYPofq
Swarm listening on /ip4/192.168.198.118/tcp/4002/ipfs/QmdtGx5n4CgWa3hNRJUTajHVSmoSPD1buNK9AYK1XYPofq
Version: 0.33.1
(node:145158) UnhandledPromiseRejectionWarning: TypeError: node.add is not a function
    at IPFS.node.on (/root/ipfs-demo/index.js:10:33)
(node:145158) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:145158) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My pacckage.json

{
  "name": "ipfs-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ipfs": "^0.33.1"
  }
}

Node 10.3.0 on CentOS 7.3

@birbird
Copy link
Author

birbird commented Dec 17, 2018

I think the right way should be

node.files.add

schollz added a commit to schollz/js-ipfs that referenced this issue Dec 21, 2018
@alanshaw
Copy link
Member

alanshaw commented Jan 3, 2019

@birbird thanks for taking the time to report this.

The examples in master have been updated to reflect the API in the upcoming release ipfs.files.add is the current (soon to be old API).

@alanshaw alanshaw closed this as completed Jan 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants