npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amokjs

v2.0.4

Published

Simple mocking framework for node.js applications

Downloads

6

Readme

amokjs - simple backend mocking framework

amokjs helps you build backend service mocks. It allows you to simply serve http responses from files. Supports multiple response codes, headers and dynamically generated values. Seen the example applications.

Since version 2.x.x amokjs supports custom plugins. We welcome community submissions!

how it works?

By default, amokjs serves responses from flat files in the responses directory in project root. It supports JSON, XML, SOAP and other formats. You can just add a new resource file into resources derectory and amokjs will serve it as response.

how to run?

Amokjs includes Express framework and your nodejs application only has to require and use npm module. See examples directory for more details.

var amokjs = require('amokjs');
amokjs.setPort("3030");
amokjs.start();

amokjs will serve response content from a file in the responses directory. There are 2 ways of requesting mocked backend responses from API powered by amok:

  • amokjs will serve response content from a file matching file name in the request path. For example if you send API request to yourapi.com/mock-api/xml mock will serve response from file named xml.

  • amokjs will serve response content from a file matching x-mock-filename header content. In this case the main request path has to be /. For example if you send API request to yourapi.com/mock-api/ and request will contain x-mock-filename HTTP header - mock will serve response from file named xml.

supported headers

Headers amokjs supports:

  • x-mock-response-code request header allows developers to request custom HTTP response code from mock API
  • x-mock-filename request header allows developers to pass mock file name in the HTTP request header rather then request path. For example if x-mock-filename: xml is used in the header and request path is / mock API will attempt to serve response from xml file.

supported template variables

In your response files you can use several template variables in order to get values generated dynamically. Below are the template values amockjs supports:

  • @date@ - will be replaced with the current timestamp. Format: YYYY-MM-DD
  • @randomDate@ - will be replaced with the random timestamp. Format: YYYY-MM-DD
  • @longid@ - will be replaced with the 10 digits long random number
  • @shortid@ - will be replaced with the random number up to 5 digits long

example curl requests

Below are few example curl requests to test the mock API:

curl -XGET 'http://localhost:3000/mock-api/xml'
curl -XGET -H 'x-mock-filename: xml' 'http://localhost:3000/mock-api/'
curl -XGET -H "x-mock-response-code: 500" 'http://localhost:3000/mock-api/xml'