Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
servemocks
Advanced tools
Starts a webserver which provides a REST API derived from JSON, XML and other sample files located in a specified directory
Contributing | Changelog | Powered by diva-e |
---|
Starts a webserver which provides a REST API derived from JSON, XML and other sample files located in a specified directory.
Consider the following directory structure:
mock-api/
├── image
│ └── logo.png
├── v1
│ ├── user
│ │ ├── 1.json
│ │ ├── 2.json
| | └── [any].json
│ ├── user.json
│ └── user.post.json
└── v2
├── health.json
└── sitemap.xml
Serving directory mock-api
with servemocks would create a webserver with the folllowing http endpoints:
Check the examples directory for more information about api conventions.
Starting from version 2 it is also possible to produce dynamic mock responses by using an ecmascript module
as mock file. Use the file extension .mjs
to enable this function.
Example: examples/v3.
# install as global package
npm install -g servemocks
# or project-local
npm add -D servemocks
servemocks <directory> [-p, --port=8080] [-c, --compact-logging]
Example:
servemocks examples/mock-api -p 5000
Servemocks is based on express and can be mounted as a submodule inside an existing app.
import { createServeMocksExpressApp } from 'servemocks';
const mainApp = express();
const options = {
responseDelay_ms: 100,
// servemocks prints every endpoint it registers to the console
// this might bloat the console log and thus you can change this setting here
endpointRegistrationLogging: 'compact', // default is 'verbose', use 'disabled' to not show any of those logs
// enable javascript code to be executed from a mock file with
// .mjs file extension
// eval can be used as alternative strategy if dynamicImport does not work
dynamicMockResponsesMode: 'eval' // one of 'disabled', 'eval' and 'dynamicImport'
}
mainApp.use('/mock-api', createServeMocksExpressApp('examples/mock-api', options))
FAQs
Starts a webserver which provides a REST API derived from JSON, XML and other sample files located in a specified directory
The npm package servemocks receives a total of 3 weekly downloads. As such, servemocks popularity was classified as not popular.
We found that servemocks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.