A simple Mockup Server for REST services that can generate fake data based on simple JSON templates.

Usage no npm install needed!

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



WIP Alpha 0.0.2 Not full tested. Not for production.

A small FAKE REST web server for your daily development.


  • Small

  • Configured via json or by an included Dashboard

  • Uses ExpressJS

  • Define an endpoint and return JSON data based on a template object

  • FakeData generator to use in templates

  • Simple NodeJS implemented localStorage instance to store things

  • Custom methods can be defined in templates

  • Can generate SVG imagen on the fly

  • Custom methods can use "Injected" arguments

    • $request // $request object containing GET/POST data
    • $localStorage // localStorage "one file" node implementation
    • $console // debug to node console from the template
    • $helper // access DataFackerHelper methods
    • $utils // access DataFackerUtils methods


You need nodejs installed and running in your system.

Clone locally the repository.

Go to your local source folder an type:

    sudo npm install -g

This will install "express-mocker" globally.

Command Line Usage


First we need to initialize our express-mocker instance in some dir. To initialize it in any wanted directory type:

express-mocker --install
express-mocker --forceInstall // Overwrites your files!!!

This will create a subdir named "express-mocker" with some config files.


In a dir containing the express-mocker dir type:


This will run express-mocker with the default config.json port and verbose options.

Now you can go to your browser and type this address to acces the dashboard.

You can also use this command line flags:

express-mocker --port <port> // sets the port
express-mocker --quiet	   // force run in quiet mode

Force exit ;-)

In the case you need to force close the port you can use this command:

express-mocker --die <port> // closes the port

Template system

Basic Templating

ExpressMocker uses a simple template system defined by a javascript object:

var jsonmocker =
    "static": "value", // static value
    "fakeName": "{{firstName}}", // run firstName helper
    "staticArray": [10, 20], // static array
    "dynamicArray": [
        "$repeat(2)", // next item in array will be repeated 2 times
            "name": "{{firstName}} {{lastName}}",
            "age": "{{random(80)}}"

This will output something like this:

    "static": "value",
    "fakeName": "Shea",
    "staticArray": [ 10,20 ],
    "dynamicArray": [
            "name": "Baron Green",
            "age": "69"
            "name": "Abdullah Gibson",
            "age": "48"

Using GET/POST vars

var jsonmocker = 

So for:


We can the take the values as:

var jsonmocker = 

Custom template methods

You can define custom methods for use in your templates.

var jsonmocker = 
    "customMethod": function(){
        return "World!!"
        return "World "+numberOfWorlds+" !!"


    "hello25":"World 25 !!"

Possible Injections in your functions

ExpressMocker uses a simple Injection system with this injections available:

  • $request // $request object containing GET/POST data
  • $localStorage // localStorage "one file" node implementation
  • $console // debug to node console from the template
  • $helper // access DataFackerHelper methods
  • $utils // access DataFackerUtils methods

Using it in your custom methods is simple as:

var jsonmocker =
    // REMEMBER!! You must put FIRST the non Injected params
    customTelephone:function( prefix, $utils )
        return $utils.replacePattern( prefix+'.4##.##.##.##');



Storing data

A special key $preprocessRequest is reserved to indicate the template that request preprocesing must be done.

Here is where we can use the $localStorage injection most time.

A simple fake GET user registration can be done via:

For this route:


var jsonmocker =
    "$preprocessRequest":function( $localStorate, $request )



Will generate a singleUserStore key with a JSON representation of the user object.

Direct raw base64 Output

A special key $content key "is reserved to indicate that the value of this key must be processed as a base64 output stream.

var jsonmocker =

This will ouput a 1pix gif image ;-) or call it with the provided image function:

var jsonmocker =

API Reference

Injectors $helper $utils
$helper firstName slug(str)
$utils lastName shuffle(array)
$scope company titleCase(str)
$localStorage email replacePattern(pattern)
$request bool randomElement(elements)
$console image(width,height) randomNumber(range)
$helper guid randomNumberRange(start,end)


The $scope object lets you access your other template methods.

    hello:function(){ return 'Hello' },
    world:function(){ return 'world!!' },
        return $scope.hello()+$;


Use it as it was the client localStorage but with disk storage.

See more at the project page:


Provides access to the query params and the processed body headers.

params( id:string ):string;
Returns the request query parameter specified by id. 
body( id:string ):any;
Returns the request body object specified by id. 


Provides a unified form ( with quiet mode ) to log messages to the console.

Supported methods:

  • log(…rest)
  • info(…rest)
  • error(…rest)
  • success(…rest)


Returns a random First Name. 

Returns a random Last Name.
Returns a random Company name.
Returns a random generated email.
Returns a random boolean value.
Returns a random base64 encoded svg image.
Returns a random Globally unique identifier.
Returns a random number of loremipsum words.
lorem( paragraphs,html=false,sentenceWords=(15-45) )
Returns a loremipsum string composed of n paragraphs.

If html is true it will add <p> tags for each paragraph.

Determine words per sentence. Default is a random value 15-45


{{slug('some long texy')}}
Returns a slugged version of str.
Returns a randomided version of the provided array.
Returns a titleCase representation of str.
Processes the provided pattern replacing:

# by a number.
U by a uppercase letter.
L by a lowercase letter.
Returns a random element from the provided array.
Returns a random number between 0 and max;
Returns a random number between start and end;