Does Express Work With WordPress?
Express and WordPress can work together via the WordPress REST API, but they serve different architectural purposes and require intentional integration rather than native collaboration.
Quick Facts
How Express Works With WordPress
Express and WordPress are fundamentally different architectures: WordPress is a monolithic PHP CMS, while Express is a lightweight Node.js framework. They don't integrate natively, but WordPress's REST API (available since 4.7) enables decoupled architectures where Express acts as a frontend layer, custom API middleware, or reverse proxy.
Common patterns include: (1) Express as a headless WordPress client consuming the REST API to render content server-side or provide custom endpoints, (2) Express serving as an API gateway that augments WordPress endpoints with additional business logic, or (3) using Express for real-time features (WebSockets, live notifications) that WordPress alone cannot provide. You're essentially running two separate applications that communicate via HTTP.
Developer experience involves managing two separate codebases, deployments, and databases. Authentication requires careful handling—you'll need to proxy WordPress credentials or use JWT tokens. This setup introduces operational complexity but provides architectural flexibility: scale Node.js independently, use modern frontend frameworks, and keep WordPress for content management only.
Best Use Cases
Express consuming WordPress REST API
npm install express axiosconst express = require('express');
const axios = require('axios');
const app = express();
const WORDPRESS_URL = 'https://your-wordpress-site.com';
app.get('/posts', async (req, res) => {
try {
const response = await axios.get(
`${WORDPRESS_URL}/wp-json/wp/v2/posts`
);
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/posts/:id', async (req, res) => {
try {
const response = await axios.get(
`${WORDPRESS_URL}/wp-json/wp/v2/posts/${req.params.id}`
);
res.json(response.data);
} catch (error) {
res.status(404).json({ error: 'Post not found' });
}
});
app.listen(3000, () => console.log('Server running on :3000'));Known Issues & Gotchas
Authentication mismatch: WordPress session cookies won't work with Express; JWT tokens require additional setup
Fix: Use WordPress JWT Authentication plugin or implement OAuth2 bridge. Proxy credentials carefully or use separate token systems for each app.
CORS errors when Express frontend calls WordPress REST API directly
Fix: Enable CORS in WordPress (via plugin or htaccess) or route all API calls through Express as a proxy to avoid client-side CORS issues.
SEO complexity: Server-side rendering in Express requires custom sitemap/meta generation since WordPress doesn't handle page metadata
Fix: Implement meta tag injection in Express, use a dedicated SEO package, or keep WordPress as the SEO source-of-truth and consume its metadata.
Database synchronization: Changes in WordPress don't auto-sync to Express caching or custom data stores
Fix: Use WordPress webhooks/action hooks to trigger Express cache invalidation, or implement polling/polling-based cache strategies.
Alternatives
- •Next.js + WordPress: Next.js provides built-in SSR/SSG with WordPress integration and better SEO out-of-the-box than Express
- •Gatsby + WordPress: Static site generation from WordPress REST API with excellent performance and hosting simplicity
- •Laravel + custom CMS: Stay in PHP ecosystem with a modern framework and build custom CMS features without WordPress overhead
Resources
Related Compatibility Guides
Explore more compatibility guides