Skip to content

Fetching Nodes

Example: Fetch a list of articles

Fetching articles is as simple as using the getNodes method:

const articles = await client.getNodes('article', '', apiParams);

In a real example it looks like this:

import { cookies } from 'next/headers';
import Image from 'next/image';
import { format } from 'date-fns';
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
import { NodeHiveConfig } from '@/config/nodehive.config';
import { createServerClient } from '@/lib/nodehive';
export default async function ArticleList() {
const client = createServerClient();
// Add filters and limit
const apiParams = new DrupalJsonApiParams();
apiParams.addSort('created', 'DESC');
//apiParams.addFields('node--article', ['field_image']);
//apiParams.addFilter('', 'ai','=')
const articles = await client.getNodes('article', '', apiParams);
return (
<section data-paragraph-type="ArticleList">
<h2 className="mb-4 text-4xl font-bold tracking-tight text-zinc-800 sm:text-5xl">
{title && title}
<div className="bg-white text-black">
<ul className="divide-y divide-gray-300">
{, index) => (
<li key={index} className="flex justify-between gap-4 py-3">
className="truncate font-medium text-red-600 hover:text-red-700"
{!article.status && (
className="mb mr-5 border-l-4 border-yellow-500 bg-yellow-100 p-4 text-yellow-700"
<span className="font-bold">Unpublished.</span>
<summary>JSON Output</summary>
<pre className="rounded-md bg-black p-8 text-xs text-slate-50">
{JSON.stringify(articles, null, 2)}