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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-rest-emulator

v1.2.0

Published

A simple stand alone mock server that uses rest-emulator

Downloads

20

Readme

Node rest emulator

A simple stand alone mock/emulator server that uses rest-emulator.
It serves as a static file server which uses json files to configure the rest responses.

Installation

npm install node-rest-emulator

Usage

Since I created it for my frontend websites which need to mock rest repsonses you can only use it directly or through package.json.

For example npm run mock-server with your package.json:

"scripts": {
  "mock-server": "mock-server config.json"
}

If there is any interest I will make it exportable, so you can use codewise.

Configuration

{
    port: 3000,
    // The directory where all the mock files are (json only), it will traverse the directory recursively
    dir: '/mocks',
    // An array of directories to serve static files
    root: ['./'],
    corsEnable: true,    
    // If set to true it will serve rewriteTemplate for 'GET /' requests
    rewriteNotFound: false,
    rewriteTemplate: 'index.html',
    // Custom headers to set for every rest response
    headers: {}
};

Example js file

It also supports to read js files. These files will be included through require. So you can use functions etc. to configure your responses. For example:

const _ = require('lodash');
module.exports = {
    "/api/random": {
        "GET": {
            "data": _.sample([1,3,4,5,111])
        }
    }
}

This configuration will return for each request to api/random one of those specified numbers.

Example json file

{
    "/api/users": {
        "GET": {
            "default": {
                "data": [{
                    "name": "John"
                }, {
                    "name": "Adam"
                }],
                "code": 200,
                "timeout": 0
            },
            "blank": {
                "data": [],
                "code": 200,
                "timeout": 0,
                "headers": {
                    "ETag": "12345"
                }
            },
            "increase": {
                "data": [{
                    "name": "John"
                }, {
                    "name": "Adam"
                }, {
                    "name": "Clark"
                }, {
                    "name": "Earl"
                }],
                "code": 200,
                "timeout": 0
            }
        },
        "POST": {
            "default": {
                "data": {
                    "success": true
                },
                "code": 201
            },
            "error": {
                "code": 405
            }
        }
    },
    "/api/cities": {
        "GET": {
            "data": [{
                "name": "New York"
            }, {
                "name": "Miami"
            }],
            "query": {
                "name=Miami": {
                    "data": [{
                        "name": "Miami"
                    }]
                },
                "name=New York": {
                    "data": [{
                        "name": "New York"
                    }]
                }
            }
        }
    }
}

For more information see gulp-rest-emulator and rest-emulator