Node.js compatibility layer for Closure Next, providing server-side rendering capabilities and module system compatibility.
npm install @closure-next/node
import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';
const html = renderToString(MyComponent, {
title: 'Server-rendered component'
});
import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';
const html = renderToString(MyComponent, {
title: 'Server-rendered component'
});
- 🖥️ Server-side rendering
- 📦 CommonJS support
- 🔄 ESM compatibility
- ⚡️ Full TypeScript support
- 🧹 Automatic cleanup
Renders a Closure Next component to an HTML string.
-
ComponentClass
: Constructor - The Closure Next component class -
props?
: Object - Props to pass to the component
A string containing the rendered HTML.
import { renderToString } from '@closure-next/node';
import type { Component } from '@closure-next/core';
interface MyComponentProps {
title: string;
}
class MyComponent extends Component {
// Implementation
}
const html = renderToString<MyComponent>(MyComponent, {
title: 'Hello' // Type-checked
});
import express from 'express';
import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';
const app = express();
app.get('/', (req, res) => {
const html = renderToString(MyComponent, {
title: 'Server-rendered page'
});
res.send(`
<!DOCTYPE html>
<html>
<body>
${html}
</body>
</html>
`);
});
import type { NextApiRequest, NextApiResponse } from 'next';
import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const html = renderToString(MyComponent, {
title: 'API-rendered component'
});
res.status(200).json({ html });
}