1 | # Marko + HTTP Server
|
2 |
|
3 | See the [marko-http](https://github.com/marko-js-samples/marko-http) sample
|
4 | project for a working example.
|
5 |
|
6 | ## Installation
|
7 |
|
8 | ```bash
|
9 | npm install marko --save
|
10 | ```
|
11 |
|
12 | ## Usage
|
13 |
|
14 | ```js
|
15 | require("marko/node-require").install();
|
16 |
|
17 | const http = require("http");
|
18 | const server = http.createServer();
|
19 |
|
20 | const port = 8080;
|
21 | const indexTemplate = require("./index.marko");
|
22 |
|
23 | server.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 |
|
34 | server.listen(port, () => {
|
35 | console.log(`Successfully started server on port ${port}`);
|
36 | });
|
37 | ```
|