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

@ashvajs/mock-server

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ashvajs/mock-server

[![npm](https://img.shields.io/npm/dm/@ashvajs/mock-server.svg)](https://www.npmjs.com/package/@ashvajs/mock-server) [![npm](https://img.shields.io/npm/v/@ashvajs/mock-server.svg)](https://www.npmjs.com/package/@ashvajs/mock-server)

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
0
Weekly downloads
 
Created
Source

@ashvajs/mock-server

npm npm

Description

Simple mock server to serve static/dynamic routes for mock api.

Usage

Create your mock server object with mock server class and pass express app object with folder path.

Folder structure

mocks
..api
....v1
......product
........[product] // serves /api/v1/product/[apple|banana|<var>]/list-items
.........list-items
............get.json // serves /api/v1/[apple|banana|any]/list-items [get method]
............post.json // serves /api/v1/[apple|banana|any]/list-items [get method]
......test // route
........post.json // serves as /api/v1/test [post method]
........get.json // serves as /api/v1/test [get method]
........delete.json // serves as /api/v1/test [delete method]
........patch.json // serves as /api/v1/test [patch method]
......dynamic // route
........post // for dynamic routes
..........index.js 
........get
..........index.js

Example

ES6

import path from 'path';
import express from 'express';
import { MockServer } from '@ashvajs/mock-server';
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
const app = express();
const mockserver = new MockServer(
  {
    staticApiPath: path.resolve('apps/mock-server-example/mocks'),
  },
  app
);
mockserver.init();

app.listen(port, host, () => {
  console.log(`[ ready ] http://${host}:${port}`);
});

Javascript

const path = require('path');
const express = require('express');
const { MockServer } = require('@ashvajs/mock-server');
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
const app = express();
const mockserver = new MockServer(
  {
    staticApiPath: path.resolve('apps/mock-server-example/mocks'),
  },
  app
);
mockserver.init();

app.listen(port, host, () => {
  console.log(`[ ready ] http://${host}:${port}`);
});

Examples

see apps/mock-server-example

FAQs

Package last updated on 22 Aug 2024

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