How to publish ipfs hash by a js code


const addr = '/ipfs/QmbezGequPwcsWo8UL4wDF6a8hYwM1hmbzYv2mnKkEWaUp'
ipfs.name.publish(addr).then(function (res) {
  // You now receive a res which contains two fields:
  //   - name: the name under which the content was published.
  //   - value: the "real" address to which Name points.
  console.log(`https://gateway.ipfs.io/ipns/${res.name}`)
})

have tried this getting the error “Unexpected token i in JSON at position 0”
one more question, if have a file on ipfs and we have need to append new data in that file. so how can we do that from js-ipfs?
for example==> first file (file.txt) which have a simple text “hello world”.
now i want to append new line in same file “Thank you !”
and the expected result should be in file.txt ==> “Hello world Thank you !”.