How to get the count of your followers on by Tobias Quante

How to get the count of your followers on

Tobias Quante

Tobias Quante

You can see how many followers you can see in your dashboard. But there are scenarios where you'd like to have them available elsewhere, say on a personal blog or portfolio.

Table of contents

Note: There's a PR on the Forem repo open for this. Check out if it has been implemented before trying this!

Fortunately, Forem ships with a REST API. At the time of writing this article, it did not support the follower count for the active user natively. For you as a developer, this should be no obstacle to calculating them yourself.

Setting up the project

Prepare the project directory

This project will consist of a single "index.js" file that you can deploy anywhere. I recommend using an Nginx reverse proxy and pm2 to keep the service running.

  1. Change into a directory of your choice and initialize a new NPM project.
  2. Install "express" and "axios"
cd /path/to/project
touch index.js
npm init -y
npm i express axios 

Generate a API token

Head over to your profile and create an API key. The option is at the bottom of the page.

  1. Enter a name for your key
  2. Click on "Generate API key"
  3. Copy it to the clipboard
  4. Head over to secrets.
  5. Create an entry with the name "DEVTO_API_KEY"
  6. Paste your API key into the value field

Add some boilerplate

Add the following code to your index.js file. Make sure to update the API_TOKEN with your secret. Even better: Use the dotenv NPM package to keep your code free of secret keys.

const express = require('express');
const axios = require('axios');
// You can request a token here: (scroll down to bottom)
const API_TOKEN = 'super-secret';
const CACHE_LIFETIME = 1000 * 60 * 60 * 4; /* 4 hours */
const PORT = 3000;

const app = express();
let cache = {
	followers: {
		count: 0,
		entries: [],

const gatherFollowerCount = async () => {
	cache.followers.count += 1;

// Interval to update cache
setInterval(() => {
	console.log('Updating cache');

app.get('/', (req, res) => {
	res.send({ followers: cache.followers.count });

app.listen(PORT, () => {
	console.log('Listening on port ' + PORT);

Then, run it:

node index.js

This piece of code

  • Create an express server on port 3000
  • Maintains an in-memory cache for your followers
  • Updates this cache every 4 hours using the "gatherFollowerCount" function
  • Sends the cache to a client requesting it on the root path
Stay fair, don't overuse the API!
Every API call you make causes traffic, which in turn costs money. If you have a lot of followers, the sum of your requests might be huge. In this case, please adjust your cache lifetime to a higher value.
If you're beyond the 10k, please also consider implementing a queue for your API requests with a generous delay in between

Visit http://localhost:3000 in your browser to check if everything works as expected.

Calculate your follower count

Add the following to the "gatherFollowerCount" function.

const gatherFollowerCount = async () => {
	const perPage = 100;
	let page = 0;

	const fetchFollowers = async () => {
		const url = `${page}&per_page=${perPage}`;

		const response = await axios.get(url, {
			headers: {
				'api-key': API_TOKEN || '',

		cache.followers.entries = [, ...cache.followers.entries];
		cache.followers.count = cache.followers.entries.length;

		if ( === perPage) {
			await fetchFollowers();

	await fetchFollowers();

This code

  • recursively gathers all followers from the API
  • adds them to your cache
  • and updates the follower count

Restart the server and check http://localhost:3000. You should see your follower count in the browser now, ready to be implemented for your personal blog or portfolio.

PS: You can apply the same practice to other stats that might not yet be part of the official API.

Share this article