How to point prerender-node at a different prerender service: the service URL and the token
Your app already registers prerender-node, and you want crawler requests to go to a different prerender service, such as your own Prerender server. You change two values. Set the PRERENDER_SERVICE_URL environment variable to the new service's address, or call set('prerenderServiceUrl', '<new url>') where the middleware is registered. Then set PRERENDER_TOKEN, or call set('prerenderToken', ...), to that service's token. A value set in code wins over the environment variable, so if you have both, change or delete the one in code. Leave the rest of your middleware setup alone.
The catch is where those values live. prerender-node uses a value set in code before it looks at the environment variable. So if your app calls set('prerenderServiceUrl', ...) or set('prerenderToken', ...), changing the environment does nothing. Find every place the values are set first, then change them.
Where prerender-node gets the service URL
The middleware checks if the request is from a crawler by checking the user agent string. For a crawler request, it builds the address it calls from the service URL followed by your page's full URL. In the source, that's this return line:
return prerenderUrl + forwardSlash + fullUrl;The service URL itself comes from a single line. It's worth reading because it decides which of your settings wins:
return this.prerenderServiceUrl || process.env.PRERENDER_SERVICE_URL || 'https://service.prerender.io/';Read it left to right. A value set in code with set('prerenderServiceUrl', ...) wins. If there isn't one, the PRERENDER_SERVICE_URL environment variable is used. If neither is set, requests go to the default, https://service.prerender.io/.
Find every place the values are set
Before you edit anything, search the server code and your deploy config for both settings. This one is easy to miss. If the token was set in code once and an environment variable was added later, that environment variable never takes effect.
grep -rn "prerenderServiceUrl\|PRERENDER_SERVICE_URL\|prerenderToken\|PRERENDER_TOKEN" .Run it from the project root, and check your host's environment settings too. If you find a value in code and another in the environment, the code one is what runs today.
Change the service URL
The prerender-node README shows these ways to set it. Pick one and remove the rest, so there's only one value to reason about later.
$ export PRERENDER_SERVICE_URL=<new url>
$ heroku config:set PRERENDER_SERVICE_URL=<new url>
app.use(require('prerender-node').set('prerenderServiceUrl', '<new url>'));- Environment variable: set PRERENDER_SERVICE_URL wherever your app reads its environment (your shell, a process manager, or your host's config screen). Then restart the app.
- In code: pass the new address to set('prerenderServiceUrl', ...) where the middleware is registered. This overrides any environment variable.
- One value only: if you move to the environment variable, delete the set('prerenderServiceUrl', ...) call, or it keeps winning.
Change the token too
The token travels in a request header, and it follows the same order as the URL: code first, then the environment. This is the line in the source:
options.headers['X-Prerender-Token'] = this.prerenderToken || process.env.PRERENDER_TOKEN;Prerender.io's Node.js guide tells you to add the following line before any route handlers: app.use(require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'));. If you followed it word for word, your token is in code. The same guide says "Do not commit your real token to a public repository".
So while you're switching anyway, move the token to PRERENDER_TOKEN and delete the hardcoded one. Then the switch, and any later one, is a config change with no code edit.
What the crawler gets when the service says no
Here's the part that hurts if you skip testing. When the service answers, prerender-node writes that answer's status code and headers back to the crawler:
res.writeHead(prerenderedResponse.statusCode, prerenderedResponse.headers);In short, if the new service rejects your token, the crawler gets that rejection's status code. Change the URL and the token in the same deploy, then check the response straight away.
If you run your own Prerender server
The open-source Prerender project describes itself like this: "Prerender is a node server that uses Headless Chrome to render HTML, screenshots, PDFs, and HAR files out of any web page." After you start it locally, its README says it will be running on http://localhost:3000, and it tells you to point your middleware at it:
export PRERENDER_SERVICE_URL=http://localhost:3000Use that address only when the Prerender server runs on the same machine as your app. In production, point it at the address your app reaches the server on.
Check the switch before crawlers see it
Fetch a page the way a crawler does and read what comes back. Don't stop at a success status. Compare the content with what a visitor sees.
curl -s -i -A "$CRAWLER_USER_AGENT" "$PAGE_URL" > crawler.htmlSet CRAWLER_USER_AGENT to a crawler user agent your middleware is set up to detect, and PAGE_URL to one of your pages.
- Status line: look at the top of crawler.html. If you see a rejection status there, check the URL and the token first.
- Content: open the file and look for your page's real text, headings and links, not just an empty app shell.
- Visitors: load the same page in a normal browser and confirm it's unchanged.
- The README's own check: you should see the static HTML version of the page with the script tags removed. If you still see them, that means the middleware isn't set up properly yet.
- Prerender.io's check: its Node.js guide tells you to look for the x-prerender-request-id response header. Whatever service you point at, judge the HTML itself too.
If you're switching to RenderSwap
We make RenderSwap, a hosted prerender service, and it fits this exact setup. You change the service URL to RenderSwap's and the token to a RenderSwap token; your middleware stays. A Prerender.io token gets a 401 from RenderSwap, so both values change. On 4 November 2026 we ran the unmodified prerender-node 3.8.3 middleware against it, and 8 of 8 swap checks passed.
A few things to know before you flip it. RenderSwap renders only domains you've verified with a TXT record in DNS, and an unverified domain gets a 403. When a render fails, the crawler gets your origin's own page. Free covers 1 verified domain and 500 fresh renders or 1 browser hour a month, whichever comes first. Pro is $19 a month for 30,000 fresh renders or 30 browser hours a month, whichever comes first. RenderSwap is not affiliated with or endorsed by Prerender.io.
Sources
- prerender-node middleware README on GitHub
- prerender-node middleware source code (index.js)
- Prerender.io Node.js integration guide
- open-source Prerender server README
Questions
Does PRERENDER_SERVICE_URL override a service URL set in code?
No. prerender-node uses a value passed to set('prerenderServiceUrl', ...) first, then the PRERENDER_SERVICE_URL environment variable, then the default, https://service.prerender.io/. Remove the code value if you want the environment variable to take effect. The token works the same way with set('prerenderToken', ...) and PRERENDER_TOKEN.
Do I have to replace prerender-node to switch prerender services?
No. You change the service URL and the token. The rest of your middleware setup stays as it is.
Can I install prerender-node inside my React, Angular or Vue project?
No. Prerender.io's Node.js guide says it cannot be installed directly into a React, Angular, or Vue project.
Related
- Can Google see your React content? How to check with the URL Inspection tool
- How to test that your prerender setup works: fetch the page as a crawler and read the HTML
- npm install prerender fails with "Failed to locate: CL.exe" on Windows: what it means and the fix
- Prerender service down or timing out? Make prerender-node fall back to your own page