GitHub auto README with NODEJS, github-actions and Hashnode API

GitHub auto README with NODEJS, github-actions and Hashnode API


5 min read

Hi everyone. As you all know Github has introduced new feature to add a README to your Github profile. We will use this feature to show our latest blogs on our Github Profile. We are using:

  1. Github Actions
  2. A Nodejs Script to Call Hashnode Api.

Node js Script

Hashnode api uses Graphql query to fetch data. So the quer to fetch our posts is:

const query = `
      user(username: "amitchambial") {
        publication {

To call the api we will uses node-fetch package

const result = await fetch('', {
        method: 'POST',
        headers: {
            'Content-type': 'application/json',
        body: JSON.stringify({ query }),
const ApiResponse = await result.json();

We will get a json response . Now we want to parse is json to markdown.

const posts = => {
        return `
### [${d.title}](${d.slug})
<img src="${d.coverImage}" height="100" />

Next we will have a defined format for our and we will add this post string there

const markdown = `
![Hello everyone πŸ‘‹](
I am Amit Chambial , A Full stack developer. 

I love to contribute to open-source software on GitHub. I am working for JP Morgan Chase as a Software Engineer I. 

I have also worked as a Freelancer and I am a five star freelancer. 

My moto is Make to Learn thats why i have made lots of projects as you can see. I love to make side projects. See my [Producthunt]( and [Gumroad]( seller page

# My Blogs


Last step is to write this makdown to our

fs.writeFileSync('./', markdown)

That's it.

Final Script

Configuring the Repo

Create a folder scripts/js. Add this script update_readme.js there.

Github Action

  1. Go to actions tab πŸ‘‰ New Workflow πŸ‘‰ set up a workflow yourself .
  2. Now add the below code there
# Name of your workflow
name: README Update
# Triggers to run workflow
  # workflow_dispatch allows to run your workflow manually
  # Run workflow based on specific schedule
  # This workflow will run every day at 00:00 UTC.
  # You can use if cron syntax is
  # looking weird for you
  - cron: "0 0 * * *"

  # This workflow contains a single job called "perform"
    # The type of runner that the job will run on
    # ubuntu-latest is default
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    # This line to work properly with repo
    - uses: actions/checkout@v2
    # This one to activate node magic
    - uses: actions/setup-node@v1
        node-version: '12.x'
    - run: npm install node-fetch
    - name: Run script
      # Here we are setting our secret API Key
      # Details:
#       env:
#         HASHNODE_API_KEY: ${{ secrets.HASHNODE_API_KEY }}
      run: node ./scripts/js/update_readme.js
    # Our script updated, but we need to commit all changes
    - name: Commit and push if changed
      run: |
        git add .
        git diff
        git config --global ""
        git config --global "GitHub Action Bot"
        git commit -m "Updated README" -a || echo "No changes to commit"
        git push

Start commit.

Now return to actions tab πŸ‘‰ click on your Workflow πŸ‘‰ run your workflow.


After workflow will be finished, go to your account page and enjoy it!

You can follow my repo and grab all ready to use code: