abidibo.net

How to mock websocket endpoints

npm js mock nodejs

Have you ever need to mock some sort of websocket endpoint during the early stage of development of an application? I do. I could easily mock REST apis with json-server, but then I had to wrote something allowing me to mock sokects also.

The result is ws-server-ftw (ws-server was taken on npm, uh). Let's start with a screencast...

Basically, ws-server-ftw provides a way to easily mock websocket endpoints, serving a json file or a js file exporting an object. Using the js format you can randomize things, ws-server-ftw reloads the input database before any send action, so random stuff get updated!

Pressing Enter in the cli let's you send the data again, so in order to send different data you can just edit the db file and then hit Enter, or you can use some commands that the cli provide: merge, deepmerge, append and custom data.

All this stuff is explained in detail in the repository page, so I'll not repeat it here.

At the moment incoming messages are just printed to the console, maybe in the future I'll add more features though. As always collaboration and PR are welcome!

ws-server-ftw repository

Let me know what do you think about it! Cheers.

Subscribe to abidibo.net!

If you want to stay up to date with new contents published on this blog, then just enter your email address, and you will receive blog updates! You can set you preferences and decide to receive emails only when articles are posted regarding a precise topic.

I promise, you'll never receive spam or advertising of any kind from this subscription, just content updates.

Subscribe to this blog

Comments are welcome!

blog comments powered by Disqus

Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured