DEV Community

Igor Irianto
Igor Irianto

Posted on • Updated on • Originally published at

How to download all your DEV articles in markdown format

Update: Looks like the dev API has changed. I added a new params option to get max 1000 articles.

We can agree that DEV is the best site for devs in the world. What if you want to cross-post your dev articles into your own personal blog site, but too lazy to copy-paste each post? 😴

I used to copy paste every single article I wrote into my personal site, but quickly found it tedious. I created a script to easily generate DEV articles.

There are two ways to do this: work from the script below or clone the Github repo.

The script

Here is main script. It is pretty short. It uses axios to fetch the data and dotenv to store secrets.

const axios = require('axios')
const fs = require('fs')
const path = require('path')
const URL = ''

const options = {
  headers: { 'api-key': process.env.DEV_KEY },
  params: { 'per_page' : 1000 }

const contentDir = '/content/'
const contentPath = __dirname + contentDir

  .get(URL, options)
  .then(response => { => {
      const normalizedTitle = article.title
        .replace(/\s+/g, '-')
        .replace(/[^a-zA-Z0-9-]/g, '')
      const normalizedPublishedAt = article.published_at.split('T')[0]
      const fileName = `${normalizedPublishedAt}_${normalizedTitle}.md`

      console.log(`${contentDir}${fileName} created!`)
    console.log('*** data successfully fetched ***')
  .catch(error => {
    console.log('ERROR: ', error)

Enter fullscreen mode Exit fullscreen mode

DEV API makes it very easy to do it. The response of the API request returns an array of all articles you've written.

I extracted the markdown content, renamed the file with (I also removed the unique ID at the end, ex: .../your-article-title-1a2b).

The repo

I also created a github repo:

Just clone the repo, install all dependencies, and create content/ directory in project root. Don't forget to give it your .env information!

git clone
cd dev-fetch-articles
npm install
mkdir content
mkdir .env
// create a key called DEV_KEY and give it your dev key values from site
Enter fullscreen mode Exit fullscreen mode

You can find your DEV_KEY secret inside Settings -> Account on site.

Once done, just run npm run fetch-dev. You will find all your articles inside content/ folder you just created. You can use this script into your app or use this script to generate content that you can copy to your app.

Making it better

If you see how the code can be improved, feel free to submit PR on Github or drop in the comment below.

Thanks for reading and happy blogging! 📖🔥

Top comments (9)

xanderyzwich profile image
Corey McCarty • Edited

I'm currently using the 11ty static site generator blog and publishing to a personal domain (from markdown) and listens to the rss to pick up articles automatically. All I have to do is change published value in the front matter to true and it publishes.

iggredible profile image
Igor Irianto

Oh, I've heard of Eleventy last year, I think. That's a cool strategy. I will have to take a look at the rss thing!
Thanks for the input 😁. Really appreciate it!

gabbersepp profile image
Josef Biehler

Thanks for mentioning this. Maybe I try this out.

gabbersepp profile image
Josef Biehler • Edited

I am not sure if this will also solve this problem. But I use the approach mentioned here:

This works without any effort and using this you could reference your repository from your personal blog or publish blog posts to and to your personal blog during build.

Nice idea!

iggredible profile image
Igor Irianto

Really good link. Thanks Josef! I wasn't aware of this method. This is actually really cool. I have had GH account for several years but I never used template option.

Really good link! 👍 Thank you very much!

rhymes profile image

Hi Igor! Nice post and usage of the API!

There's also a third option: you can request an export of your content, you can find it here at the bottom of the page:

iggredible profile image
Igor Irianto

I didn't know this feature exists! 😅

shijiezhou profile image
Shijie Zhou

Right @rhymes , I had done that before, but I think using the api can keep your article update without download the export json each time.

rhymes profile image

Agree :) It's easier to script!