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

quick-mock-server

v1.1.2

Published

This is a tool to create a web server and mock data quickily. It consists of [express](https://github.com/expressjs/express) and [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).

Downloads

17

Readme

Introduction

This is a tool to create a web server and mock data quickily. It consists of express and http-proxy-middleware.

Usage

Installation

npm install --save-dev quick-mock-server

Configuration

You can create a configuration file named .proxyrc, .proxyrc.json or .proxyrc.js in the project root directory. In this file, it must be or export a json object.
This json object is like this:

{
    "options": {
        "target": {
            "host": "localhost",
            "port": 9000
        },
        "pathRewrite": {
            "^/api/": ""
        }
    },
    "public": [
        "public",
        "mock"
    ]
}

The options is equal to http-proxy-middleware and the public is the static folders using express to achieve.

Addition:
To make it easier to map interfaces to JSON files, I added the $ symbol in pathRewrite to represent path variables.For example:

{
    "options": {
        "pathRewrite": {
            "^/api/$": "/$.json"
        }
    },
    "public": [
        "mock"
    ]
}

If you request the url /api/user, it will be changed to request /user.json. Now, if you have a user.json file in mock folder, you can get its data.

Initalization

var startServer = require('quick-mock-server')
startServer()

Quick Start

  1. create a folder named example and run the following cmd in this folder
npm init
npm install --save-dev quick-mock-server
  1. make the project with following structure:
   example
   |
   |---- mock
   |      |
   |      |---- test.json
   |
   |---- public
   |      |
   |      |---- index.html
   |
   |---- .proxyrc
   |
   |---- index.js
   |
   |---- package.json
  1. Files content

// index.js

var startServer = require('quick-mock-server')
startServer()

// .proxyrc

{
    "options": {
        "target": {
            "host": "localhost",
            "port": 9000
        },
        "pathRewrite": {
            "^/api/$": "/$.json"
        }
    },
    "public": [
        "public",
        "mock"
    ]
}

// public/index.html

<!Doctype html>
<html>
    <head>
        <meta charset = "utf-8" />
        <script src = "https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>
    </head>
    <body></body>
    <script>
        axios.get('/api/test').then(function(res) {
            document.write(JSON.stringify(res.data))
        })
    </script>
</html>

// mock/test.json

{
    "key1": "val1",
    "key2": "val2",
    "key3": "val3",
    "key4": "val4",
    "key5": "val5"
}

// package.json

{
    ....
    "main": "index.js",
    "script": {
        "start": "node ."
    }
    ...
}
  1. open the terminal, run npm start. You can see server has been started, listening in port 9000 output in terminal if no error.
  2. open http://localhost:9000 in browser, and you can see the data of mock/test.json in web page.