HTTP server for running approvals from the browser

Usage no npm install needed!

<script type="module">
  import approvalsServer from '';


approvals-server NPM version

A simple node HTTP server for running approval tests from the browser.


If you use npm, then install the package via npm.

npm install approvals-server

If you're not using npm, simply copy the file index.js to a directory of your choice.

Server setup

var approvalsServer = require('approvals-server')();

Configuring the server

var approvalsServer = require('approvals-server')({
    approvals: {},		// See for all config options
    port: 1338,			// Default port
    path: './'			// Default path

If you need to you can manipulate the filenames by overriding the testNamer function like this:

var config = {
    testNamer: function (name) {
        return name.replace(/\W+/g, '-');


To verify, do a POST to "http://localhost:1339/verify".


  "testName": "The name of the test",
  "data": "String to compare"

From the browser

The simplest thing possible is to do something like this.

function verify(test, data) {
    var xhr = new XMLHttpRequest();'post', 'http://localhost:1339/verify', false);
    xhr.send(stringify({ testName: test, data: data }));
    return xhr.status === 200;

var data = {
    "Name": "Kristoffer",
    "Age": "Unknown"

verify('MyTest', JSON.stringify(data, null, 2));

Using curl

curl -H "Content-Type: application/json" -d '{ "testName": "Footest", "data": "Bar" }' http://localhost:1338/verify

More about Approvaltests