JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q30654F

Node.js integration for Closure Next framework

Package Exports

  • @closure-next/node
  • @closure-next/node/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@closure-next/node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Closure Next Node.js Integration

Node.js compatibility layer for Closure Next, providing server-side rendering capabilities and module system compatibility.

Installation

npm install @closure-next/node

Usage

ESM

import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';

const html = renderToString(MyComponent, {
  title: 'Server-rendered component'
});

ESM

import { renderToString } from '@closure-next/node';
import { MyComponent } from './my-component';

const html = renderToString(MyComponent, {
  title: 'Server-rendered component'
});

Features

  • ๐Ÿ–ฅ๏ธ Server-side rendering
  • ๐Ÿ“ฆ CommonJS support
  • ๐Ÿ”„ ESM compatibility
  • โšก๏ธ Full TypeScript support
  • ๐Ÿงน Automatic cleanup

API Reference

renderToString(ComponentClass, props?)

Renders a Closure Next component to an HTML string.

Parameters

  • ComponentClass: Constructor - The Closure Next component class
  • props?: Object - Props to pass to the component

Returns

A string containing the rendered HTML.

TypeScript Support

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
});

Server-Side Usage

Express Example

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>
  `);
});

Next.js API Route Example

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 });
}