Automatically Validate HTML with Node.js and Valimate

  • Compatibility with newer browsers and user agents
  • A stronger foundation for accessibility enhancements (e.g. the alt attribute on image elements)
  • A DOM that is potentially more efficient to parse, as a compliant structure is arguably more predictable
  • A perception of professionalism within the software engineering community

Getting Started

In order to use Valimate, you must have Node.js v4 or later running on your machine. Install the CLI globally in your terminal.

npm i -g valimate
{
"urls": [
"http://jamesswright.co.uk/",
"https://github.com"
]
}
valimate
Using Valimate to validate two websites

Validating Local Node.js HTTP Servers

Here’s a hypothetical: say we have a continuous integration server that runs tests against any code that we push to our repository. Wouldn't it be nice to also validate our HTML on check in, so we can determine that our latest changes haven’t compromised our markup? If your application is written in Node.js, then it’s possible to run it as a child process via Valimate.

npm init
npm i --save valimate-notifier
'use strict';const http = require('http');
const notifyValimate = require('valimate-notifier');
const PORT = 8081;const HTML = `
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<section role="main">
<h1>Valimate Test Server</h1>
<li>This is some invalid, dummy HTML</li>
</section>
</body>
</html>
`;
http.createServer((req, res) => res.end(HTML, 'utf-8'))
.listen(PORT, () => notifyValimate(true));
{
"localAppServer": {
"entryPoint": "app.js"
},
"urls": [
"http://localhost:8081"
]
}
<section role="main">
<h1>Valimate Test Server</h1>

<p>This is some valid, dummy HTML</p>
</section>

Final Thoughts

Thank you so much for reading this article and for giving Valimate a go. The project is based upon a similar solution that I implemented for my project at work, so I hope that other developers find it useful.

--

--

Software engineer, writer, speaker, and open source contributor. Worked at the likes of Sky, Channel 4, YLD, Trainline, and NET-A-PORTER.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
James Wright

James Wright

Software engineer, writer, speaker, and open source contributor. Worked at the likes of Sky, Channel 4, YLD, Trainline, and NET-A-PORTER.