Mammock is a node.js service mocking framework designed to be quick and easy, allowing developers to fill the "missing gaps" in services during development.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

mammock Build Status Dependency Status Coverage Status

Mammock is a node.js service mocking framework designed to be quick and easy, allowing developers to fill the "missing gaps" in services during development. Mammock is still under heavy development, but has already proven itself extremely useful as part of a UI developers toolkit. Using the default method for locating resources, the directory structure is well-suited for any modern SCM. Using the command line interface, even non-developers can quickly pull the latest version of the mock environment from SCM and have a mocked service up and running in moments. In load tests, Mammock has shown to handle an exceptionally large number of requests efficiently, ensuring that even the most hostile web application will perform as expected.

Getting Started

Install the module with: npm install mammock

The command line script and library can also be installed globally, with: npm install -g mammock

Note: To install globally, it may be necessary to become a superuser on your OS with a command such as sudo.


Basic Usage

USAGE: node mammock [--port <ARG1>] [--root <ARG1>] [--silent] 
  -p, --port <ARG1>     specify the port to listen on
  -r, --root <ARG1>     root path to serve from
  -s, --silent          runs the server without console output

Adanced Usage

Here is an example node, or endpoint, in Mammock:

module.exports  = function () {
    //We create a variable to return, 'node', so that we can set properties to the functions
    var node = {
        get: function (route, request, response) {
            return {
                status: 200,
                headers: {
                    "Content-Type": "application/json"
                response: JSON.stringify({})
        post: function (route, request, response) {
            var endpoint = this,
                postData = "";

  "Now overriding the POST response...")

            request.on('data', function (data) {
      "Receiving POST data...");
                postData += data;
            request.on('end', function () {
      "Finished receiving POST data");
      "Writing header response to POST request...");
                response.writeHeader(200, {
                    "Content-Type": "application/json"
      "Writing response to POST request...");

        put: function (route, request, response, data) {
            return {
                status: 200,
                contentType: "application/json",
                response: data
        delete: function (route, request, response) {
            return {
                status: 200,
                contentType: "application/json"

    //using .delay lets you simulate basic network latency
    //both numbers and functions (that return numbers) are valid values
    node.get.delay = function () {
        return Math.floor(Math.random() * (500 - 10 + 1) + 10);

    //overriding the node allows us to handle the request manually = true;

    //setting capture on the method will allow you to have the method invoked
    //after the server has already captured the data, and pass it in as the 
    //optional fourth parameter
    node.put.capture = true;
    return node;


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History


  • Server no longer retrieves package.json data (bad ideas are bad.)
  • Server now can accept a delay parameter for individual methods (see example)
  • minor code cleanup


  • Server now retrieves package.json data
  • Server can now return the mammock version via Mammock.getVersion()
  • CLI mammock now reads the displayed version from the server
  • grunt build now runs the test task before building
  • CLI mammock can now be shutdown cleanly with Ctrl-c


  • Switched to mocha for testing, as it provides more reporters
  • Improved testing a bit
  • Switched npm test script from npm nodeunit to npm test
  • One step closer to coveralls reporting...
  • Fix for slightly outdated grunt-watch-contrib dependency (thank you gemnasium)


  • Minor fix for tests
  • Improved test mocks somewhat, but they still need some attention
  • Moved source files to live in src/, to clean up project root


  • Major rewrite of the routing engine to better suit a multitude of custom requesti methods
  • Removed Mammock.Endpoint and Mammock.Server, moving main constructor to the initial mammock instance
  • endpoints now get extended with logging abilities


  • Fixed documentation error stating the version was 0.2.5
  • Fixed major GET bug


  • Fixed build further
  • Actually ready for release


  • Cleaned up build
  • First npm publish


  • Fixed major endpoint bug, which resulted in endpoints being inaccessible
  • Fixed index routing bug


  • Added timestamps to logs
  • Added -s/--silent option to allow running the server sans output
  • Renamed bin/mammock to bin/mammock.js because no extension is stupid.
  • endpoints should now be reachable


  • First functional server running as intended.
  • Options added to command line


  • Added initial structure and got .travis.yml not being bejankity.


Copyright (c) 2013 Elden Armbrust
Licensed under the MIT license.