UNPKG

646 BMarkdownView Raw
1# Marko + HTTP Server
2
3See the [marko-http](https://github.com/marko-js-samples/marko-http) sample
4project for a working example.
5
6## Installation
7
8```bash
9npm install marko --save
10```
11
12## Usage
13
14```js
15require("marko/node-require").install();
16
17const http = require("http");
18const server = http.createServer();
19
20const port = 8080;
21const indexTemplate = require("./index.marko");
22
23server.on("request", (req, res) => {
24 indexTemplate.render(
25 {
26 name: "Frank",
27 count: 30,
28 colors: ["red", "green", "blue"]
29 },
30 res
31 );
32});
33
34server.listen(port, () => {
35 console.log(`Successfully started server on port ${port}`);
36});
37```