Skip to content

JonVisc/StaticMockServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StaticMockServer

Description

This is a node server that runs on port 3001. You pass in a JSON file and it will allow you to hit those paths / parameters by configuring your service to point to http://localhost:3001/<whatever your JSON describes, the quick example is below>

I intentionally tried to make this as lightweight as I could and without a lot of dependencies so that it is easy to configure and get running as quickly as possible.

Example

Create a json file. I would store it in the /mocks folder FYI: The example.json file is continually updated with new features whenever I update the MockServer to support them. It resides here!

{
    "exampleString": {
        "type": "get",
        "body": "Blah"
    },
    "exampleJSON": {
        "type": "get",
        "body": {
            "key": "value"
        }
    },
    "exampleJSON": {
        "type": "post",
        "body": {
            "key": "post return value"
        }
    },
    "multilevel/example": {
        "type": "get",
        "body": {
            "Allthe": "things"
        }
    },
    "headersExample": {
        "type": "get",
        "headers": [
            {"Content-Type": "application/json"}
        ],
        "body": {}
    }
}

Install

$ npm install

Start Server with File Monitoring

$ nodemon index.js mocks/example.json

or

$ npm run mon
Then head to a browser and enter the URL: http://localhost:3001/load/example.json

Start Server without File Monitoring (manually restart everytime there is a filechange)

$ node index.js mocks/example.json

or

$ npm run dev
Then head to a browser and enter the URL: http://localhost:3001/load/example.json

An important note, if you create a second json and load it http://localhost:3001/load/example2.json the routes from example.json will be cleared.

About

A Mock Server using JSON as an input

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published