Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@airquality/mock-server

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airquality/mock-server

Node mock server based on Koa

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

mock-server

Node mock server based on Koa.

  • Writing routes configuration.
  • Custom request handlers.
  • Watching file changes, and restarting server.

Install

npm install @airquality/mock-server

Usage

All .js files in cwd(current work directory) will be watched and treated as routes configuration files. Every .js file must be exported an array property routes. Every route object in routes must exist three properties: path, method and handler. The handler function will be injected a request data object. See following:

// HelloWorld.js
module.exports = {
  routes: [
    {
      path: '/',
      method: 'get',
      handler: ({ headers, params, query, body, cookies, ctx }) => {
        // You can get request data by above params.

        // Returns will be sent to client.
        return 'Hello World!'
      },
    },
  ],
}

In your package.json file, add a script to start mock server by use mock-server command.

// package.json
...
script: {
  "mock": "mock-server",
  ...
}
...

Finally, type npm run mock in your work directory.

npm run mock

Options

Set mockServerOptions in package.json file to change default options.

// package.json
...
"mockServerOptions": {
  // Default path is cwd(current work directory)
  "path": "./routes",
  // Default server port is 4000
  "port": 4001
}
...

Simulated Data

You can use faker.js to generate data.

License

MIT.

Keywords

FAQs

Package last updated on 07 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc