Weesperstraat 61-105
1018 VN Amsterdam
The Netherlands

Headless Drupal | Serving a XML sitemap of Drupal via Node.js / Express

19 Nov, 2015 Drupal
Drupal headless

In our search to develop a headless Drupal website, we stumbled across the XML sitemap. This is needed to inform search engines, like Google, about the organization of your site content and to submit content updates. As a result you will receive reports about indexed links, broken links, duplicate content and other errors on your Drupal website.

With this knowledge it is possible to implement optimizations and it let’s your Drupal website achieve a higher SEO score. You can post the XML sitemap in the Search console of Google (Tools for webmasters).

Generating a sitemap in Drupal is relatively easy with the XML sitemap module. This is a stable module that let’s you generate a sitemap relatively quickly.

But there is no such ready-to-use content in Node.js / Express JS. To put it in simple words, the content is loaded externally (from Drupal) and transferred to the client. But since the XML sitemap is essential for SEO, we searched for a way to implement it in Node.JS. Here’s how we pulled this off:

1. Install the XML sitemap module in Drupal

You can generate the sitemap via Drupal and then ‘stream’ it via Node.js / Express JS to the preferred search engine. So the first step is to produce the sitemap in Drupal, which also manages your content. If you are working on a decoupled Drupal installation, then I expect the configuration of the XML sitemap should not form any problems. But to be sure, you will find the instructions here.

2. Install the Request module in Node.JS / Express JS

After having tried several NPM modules, the Request module appeared to be most suitable and in the end a quick solution to ‘stream’ the sitemap (load and transfer). So install this module in your Node.js installation and don’t forget to import it in Node.js / Express JS, see (1) in the image below.

If you want to know more about installing NPM modules, then check Headless Drupal & Node.js | Part 2/3: Node.js introduction.

Stream the sitemap using ‘pipe’

First create a var in which you define the source of the XML sitemap in your Drupal installation (2).

app.get('/sitemap.xml', function (req, res) {
var sitemap = request(sitemapxml);
req.pipe(sitemap);
sitemap.pipe(res);
});

==> This ensures that an incoming request on /sitemap.xml transfers the sitemap from the Drupal source. So this allows the stream / pipe.

Posting the sitemap to, for example, the Google Search console is possible using the link jouwdomein.nl/sitemap.xml, where jouwdomein.nl stands for the Node.JS installation.

Done, wrap up

That’s it. While reading it seems quite easy and even more so once it works. But gathering information and testing takes a lot of time, which I hope you can now save as a result of this blog.

Questions, feedback? Let me know!

Written by Joris Snoek | Nov 19, 2015
Drupal project? Let's Talk

Please tell me all about your project!
Mail , or send a message:

Got some more time?

Related content

23 Oct 2026 Drupal

Legacy code, all cleaned up

**I had been postponing Drupal coding standards fixes in Drupal distro [OpenLucius](https://www.drupal.org/project/openlucius) for far too long. There were always more interesting things to do: fixing bugs, building new features, and improving existing functionality. While code style fixes should…

Read more →

16 Oct 2026 Drupal

There’s an incredible amount of things happening in the world of Drupal and AI. It’s very exciting, but almost impossible to keep up with. I’d been planning for a while to seriously dive into agentic coding. I feel a little late to the party, but at the same time, I get the impression that many…

Read more →

28 Sep 2026 Drupal

AI as a programming partner

A request from a product owner: their Drupal website has a content type called 'Event'. The editorial team wants to display a block on the homepage showing the next three events. ## The initial request and AI prompt > “Create a Drupal block that displays the next three events, sorted by start…

Read more →

21 Sep 2026 Drupal

With new features like: @-mentions, drag-and-drop images & general settings.

Last week we released a new version of OpenLucius: a lean and fast Drupal social collaboration distribution with features like: groups, social posts, messages, group chats, stories, file -and folder management, notebooks, categories, activity streams, notifications, @-mentions, comments and…

Read more →