UNPKG

791 BMarkdownView Raw
1# Hapi + Marko
2
3See the [marko-hapi](https://github.com/marko-js-samples/marko-hapi) sample
4project for a working example.
5
6## Installation
7
8```bash
9npm install hapi --save
10npm install marko --save
11```
12
13## Usage
14
15```javascript
16"use strict";
17
18require("marko/node-require");
19
20const Hapi = require("hapi");
21
22const indexTemplate = require("./index");
23
24const server = new Hapi.Server();
25const port = 8080;
26
27server.connection({ port });
28
29server.route({
30 method: "GET",
31 path: "/",
32 handler(request, reply) {
33 return reply(
34 indexTemplate.stream({
35 name: "Frank",
36 count: 30,
37 colors: ["red", "green", "blue"]
38 })
39 ).type("text/html");
40 }
41});
42
43server.start(err => {
44 if (err) {
45 throw err;
46 }
47
48 console.log(`Server running on port: ${port}`);
49});
50```