marko/docs/http.md
kounelios13 d7c135891b Use http variable (#1024)
Instead of requiring the http module again use the http variable.
2018-03-23 11:45:50 -04:00

646 B

Marko + HTTP Server

See the marko-http sample project for a working example.

Installation

npm install marko --save

Usage

require("marko/node-require").install();

const http = require("http");
const server = http.createServer();

const port = 8080;
const indexTemplate = require("./index.marko");

server.on("request", (req, res) => {
  indexTemplate.render(
    {
      name: "Frank",
      count: 30,
      colors: ["red", "green", "blue"]
    },
    res
  );
});

server.listen(port, () => {
  console.log(`Successfully started server on port ${port}`);
});