Twitter: raymondcamden

Address: Lafayette, LA, USA

Another proof of concept - MockData

12-13-2012 5,681 views Development, JavaScript 6 Comments

Yesterday I whipped up a quick little Node app that I thought folks might find interesting. The basic idea behind it is a quick way to generate fake JSON data. So imagine you are offline and need to write some code that works with an API. You could fire up this app (it runs as its own server) and then simply point your XHR code to the service. By using URL parameters you can define what type of data you would like back. Or maybe you aren't offline but simply don't have access to an API yet. Or perhaps the API you are using has strict usage limits. You get the idea I think. There's already a damn good mocking library out there (MockJax) but I wanted to build something that acted like a real server. Whether or not that make sense is up to debate. Anyway, here's an example.

If I wanted 5 objects with an author field that is a name and an age, I'd do:


Which could return:

A more complex example could add a gender and a salary, as well as returning a random number of results.


The service uses CORS which means you can be running a virtual host locally and access the URL at localhost with no issues.

Want to play with it? Want to give me feedback on the code? Just hit up the GitHub repo:


These comments will soon be imported into Disqus. To add a comment, use Disqus above.
  • Commented on 12-13-2012 at 10:52 AM
    Nice Ray. When I need to create fake server side elements, I use Maque ( It has a lot of nice features that I used to stub out my server calls when I am prototyping.
  • Commented on 12-13-2012 at 11:28 AM
    Nice. I need to start selling mine for 19.99. ;) I like the lorem ipsum generator. I had planned on adding that. Something like



    bod=lorem:4 (4 paragraphs of lorem ipsum)
  • Commented on 12-13-2012 at 11:39 AM
    Done. :)
  • Commented on 12-13-2012 at 4:19 PM
    Looks good Ray! I personally prefer MockJax because they can be used in unit testing and also doesn't require node. Just curious, what was missing from MockJax?
  • Commented on 12-13-2012 at 4:26 PM
    Not a thing. My thought process was - I don't want to include another JS library - I want to simply switch the URL from "" to "tempfornow".
  • Commented on 12-13-2012 at 4:27 PM
    Also remember I'm learning Node, so I'll be building a lot of crap. ;)