A typed, zero-dependency client for the Hashnode GraphQL API. Use Hashnode as a headless CMS from Node.js, Next.js and edge runtimes, verify Hashnode webhooks, and give AI assistants access to your blog through MCP.
Important
Since May 2026 Hashnode only serves API requests for publications on a Pro plan. Requests for other publications fail with HashnodeError code FORBIDDEN. See the Hashnode announcement.
- Features
- Install
- Quick start
- Usage
- AI coding agents
- Documentation
- Compatibility
- Versioning
- Contributing
- Security
- License
- Typed methods for posts, search, series, static pages, comments, recommendations and drafts, plus
request()for custom queries - Pagination with cursors, or
iteratePosts()to walk every post - Request de-duplication: identical queries made at the same time share one API request. Any number of concurrent calls for the same post, whether 10 or 10,000, hit Hashnode once
- Predictable errors:
HashnodeErrorwith Hashnode's error code, request timeouts andAbortSignalsupport - Next.js ready:
revalidateand cachetagsper client or per request - Webhooks: signature verification on Web Crypto and a drop-in route handler
- MCP server: let AI assistants (Claude, Cursor, VS Code Copilot) read your blog with
npx -y @jowinjohnchemban/hashnode-client - Runs anywhere: ESM and CommonJS, Node.js 22+, Deno, Bun, Cloudflare Workers and Vercel Edge
- No runtime dependencies, published with npm provenance
pnpm add @jowinjohnchemban/hashnode-clientOr use npm install, yarn add or bun add.
import { HashnodeClient } from '@jowinjohnchemban/hashnode-client';
const hashnode = new HashnodeClient({ host: 'blog.example.com' });
const publication = await hashnode.getPublication();
const { items: posts } = await hashnode.getPosts({ first: 10 });
const post = await hashnode.getPost('my-first-post'); // null if it doesn't existEvery option can also come from an environment variable (HASHNODE_PUBLICATION_HOST, HASHNODE_ACCESS_TOKEN, …; see .env.example), so new HashnodeClient() works too.
| Method | Returns |
|---|---|
getPublication() |
Publication | null |
getPosts({ first?, after?, tagSlugs? }) |
Page<BlogPost> |
iteratePosts({ first?, tagSlugs? }) |
AsyncGenerator<BlogPost> |
getPost(slug) / getPostById(id) |
BlogPostDetail | null |
searchPosts(query, { first?, after?, sortBy? }) |
Page<BlogPost> |
getSeriesList() / getSeries(slug) |
Page<Series> / Series | null |
getSeriesPosts(slug, { first?, after? }) |
Page<BlogPost> |
getStaticPages() / getStaticPage(slug) |
Page<StaticPage> / StaticPage | null |
getPostComments(postId, { first?, after? }) |
Page<Comment> |
getRecommendedPublications() |
RecommendedPublication[] |
getDrafts({ first?, after? }) |
Page<Draft> (requires token) |
request(query, variables?) |
raw GraphQL data |
All of them are described in the API reference.
const page = await hashnode.getPosts({ first: 20 });
const next = await hashnode.getPosts({ first: 20, after: page.pageInfo.endCursor });
for await (const post of hashnode.iteratePosts()) console.log(post.slug);import { isHashnodeError } from '@jowinjohnchemban/hashnode-client';
try {
await hashnode.getPosts();
} catch (error) {
if (isHashnodeError(error)) console.error(error.code, error.message); // e.g. FORBIDDEN, TIMEOUT
}All error codes are listed in the API reference. If you prefer [] or null instead of exceptions, use the convenience functions (getBlogPosts(), getBlogPostBySlug(), …).
export const hashnode = new HashnodeClient({ next: { revalidate: 3600, tags: ['hashnode'] } });// app/api/hashnode/route.ts: revalidate when you publish
import { revalidateTag } from 'next/cache';
import { createWebhookHandler } from '@jowinjohnchemban/hashnode-client/webhooks';
export const POST = createWebhookHandler({ handlers: { '*': () => revalidateTag('hashnode') } });The Next.js guide covers pages, metadata, sitemaps and search, and the webhooks guide covers webhook setup.
Give Claude, Cursor, VS Code Copilot or any MCP client read-only access to your blog:
{
"mcpServers": {
"hashnode": {
"command": "npx",
"args": ["-y", "@jowinjohnchemban/hashnode-client", "--host", "blog.example.com"]
}
}
}Tools include list_posts, get_post, search_posts, series, static pages and comments. Setup for each client is in the MCP guide.
Pass a mock fetch instead of mocking the module:
const fetch = async () =>
Response.json({ data: { publication: { post: { id: '1', title: 'Hello' } } } });
const hashnode = new HashnodeClient({ host: 'blog.example.com', fetch });The package includes an Agent Skill that teaches coding agents such as Claude Code, GitHub Copilot, Cursor and Codex how to integrate it correctly. It covers setup, the Pro-plan requirement, pagination, error codes, Next.js caching, webhooks and the MCP server. Install it into your project with the skills CLI:
npx skills add jowinjohnchemban/hashnode-client
# or from the installed package, matching your version:
npx skills add ./node_modules/@jowinjohnchemban/hashnode-clientThe skill lives in skills/hashnode-client and is tested against the code, so it stays accurate.
| Guide | Covers |
|---|---|
| Getting started | Setup, configuration and first queries |
| API reference | Options, methods, types, errors and exports |
| Next.js guide | App Router pages, caching, sitemaps, search, revalidation |
| Webhooks | Setup, verification, events and testing |
| MCP server | Using the blog from AI assistants |
| Troubleshooting | Common errors and fixes |
| Migrating from 1.x | Breaking changes in 2.0 |
| Examples | Node.js script, Next.js data fetching, webhook handlers |
| Changelog | Release history |
| Runtime | Supported |
|---|---|
| Node.js | 22, 24, 26 (tested on Linux, macOS, Windows) |
| Deno, Bun | Yes |
| Cloudflare Workers, Vercel Edge | Yes |
| Next.js | App Router and Pages Router |
| Browsers | Works, but never ship an access token to the browser |
MCP server (/mcp, hashnode-mcp) |
Node.js 22+ |
Module formats: ESM (import) and CommonJS (require), with TypeScript declarations for both.
This project follows Semantic Versioning. Releases are automated from Conventional Commits and listed in the changelog and on GitHub Releases. Every npm release is built and published by GitHub Actions with a provenance attestation.
Contributions are welcome! Read the contributing guide for setup, testing and the release process, and follow the code of conduct.
Please report vulnerabilities privately as described in the security policy.
MIT © 2025–2026 Jowin John Chemban
This project is not affiliated with Hashnode.