Write HTML in parts, <head> first, <body> later

npm install write-html
1 downloads in the last week
4 downloads in the last month


build status dependency status

Write HTML in parts, <head> first, <body> later


WriteHtml encourages you to write the <head> of your html page immediately and write the body once you have done some async things. this allows script tags, style tags & assets like link prefetching to load in parallel with your database fetching code.

var http = require("http")
var WriteHtml = require("write-html")

var server = http.createServer(function (req, res) {
    if (req.url.match(/\/user\//)) {
        var userParts = req.url.split("/")
        var userId = userParts[userParts.length - 1]

        var writer = WriteHtml(req, res)
        writer.writeHead("<head><title>User page</title></head>")

        db.get("user:" + userId, function (err, user) {
            writer.writeBody("<body>" + render(user) + "</body>")


npm install write-html


  • Raynos

MIT Licenced

npm loves you