# How to publish ipfs hash by a js code

**URL:** <https://discuss.ipfs.tech/t/how-to-publish-ipfs-hash-by-a-js-code/10303>\
**Category:** Help\
**Tags:** js-ipfs, ipns, files\
**Created:** [February 22, 2021, 6:17pm UTC](https://discuss.ipfs.tech/t/how-to-publish-ipfs-hash-by-a-js-code/10303 "2021-02-22T18:17:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prag](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@prag](https://discuss.ipfs.tech/u/prag)\
**Post date:** [February 22, 2021, 6:17pm UTC](https://discuss.ipfs.tech/t/how-to-publish-ipfs-hash-by-a-js-code/10303/1 "2021-02-22T18:17:40Z")

</div>

```auto

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 !”.
