Setting up our server

With our templating system working, let's go ahead and hook all of this up to our server. Instead of now responding with a simple message of A okay!, we will respond with our template all put together. We can do this easily by running the following code:

stream.respond({        'content-type': 'text/html',        ':status': 200    });    const file = fs.createReadStream('./template/main.html');    const tStream = new LoopingStream({        dir: templateDirectory,        vars : { //removed for readability }},        loopAmount : 2    })    file.pipe(tStream).pipe(stream);});

This should look almost exactly like our test harness. If we now head to https://localhost:50000, we should see a very basic HTML page, but we have our templated file created! If we now head into ...

Get Hands-On JavaScript High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.