Memory Profiling For Mere Mortals

Server

const http = require('http')
const fs   = require('fs')
const path = require('path')
const templateEngine = require('any-template-engine')

const header = fs.readFileSync(path.join(__dirname, 'my-header.html'), 'utf8')

// [ ...]

function onrequest(req, res) {
  const context = getContext(req);

  fs.readFile(path.join(__dirname, 'index.html'), 'utf8', function onreadIndex(err, src) {
    if (err) return console.error(err)
    const html = header + templateEngine(src, context)
    serve(html)
  })
}