JSPM

@marko/express

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 227
  • Score
    100M100P100Q87201F
  • License MIT

Render Marko templates in an express application.

Package Exports

  • @marko/express

Readme


@marko/express
TypeScript Styled with prettier Build status NPM Version Downloads

Render Marko templates in an express application.

Installation

npm install @marko/express

Examples

Setup

import express from "express";
import markoMiddleware from "@marko/express";
import Template from "./template.marko";

const app = express();

app.use(markoMiddleware());

app.get("/", (req, res) => {
  // Streams Marko template into the response.
  // Forwards errors into expresses error handler.
  res.marko(Template, { hello: "world" });
});

$global / out.global

When calling res.marko the input.$global is automatically merged with app.locals and res.locals from express. This makes it easy to set some global data via express middleware, eg:

middleware.js

export default (req, res, next) => {
  res.locals.locale = "en-US";
};

Then later in a template access via:

<div>${out.global.locale}</div>

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.