
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
mock-json-server
Advanced tools
Create a mock server using a json file.
To install, you need to have NodeJS and NPM installed on your system. Go to https://nodejs.org/en/, download and install one of the provided versions. Both NodeJS and NPM are included.
Install the mock-json-server package by running npm install -g mock-json-server
in your terminal.
Using npm v5.6.0 or later? You can skip global installation and directly run npx mock-json-server data.json
in a folder containing the below explained data.json
.
Thats it!
To run the server run: mock-json-server data.json
This starts a server on http://localhost:8000/
you can change the port by running mock-json-server data.json --port=3000
data.json
contains:
{
"/home": {
"get": {
"data": [
{"id":1,"name": "Steve"}
]
},
"post": {
"data": [
{"id":1,"name": "Steve French"}
]
}
}
}
A Get Request to http://localhost:8000/home will return.
{
"data": [
{"id":1,"name": "Steve"}
]
}
A Post Request to http://localhost:8000/home will return.
{
"data": [
{"id":1,"name": "Steve French"}
]
}
Mock json server is also a docker image. Run it with the command
docker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 8000:8000 ajoelpod/mock-json-server
Run the same command as above but with the PORT
environment variable. Also change the -p to be equal to your new port.
docker run --name mock-json-server --env PORT=3000 -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:3000 ajoelpod/mock-json-server
or
Just change the forwared ports
docker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:8000 ajoelpod/mock-json-server
Example.
version: '3'
services:
mock-json:
image: 'ajoelpod/mock-json-server'
volumes:
- ./test/data.json:/usr/src/app/data.json
ports:
- 8000:8000
const server = require('mock-json-server');
const app = server({
"/home": {
"get": {
"data": [{ "id": 1, "name": "Steve" }]
},
"post": {
"data": [{ "id": 1, "name": "Steve French" }]
}
},
"/test/:id": {
"get": {
"data": [{ "id": 1, "name": "Steve" }]
},
"post": {
"data": [{ "id": 1, "name": "Steve French" }]
}
}
}, 8000); // Start the server with a JSON object;
// Start the server;
app.start();
// Reload the server with new data;
app.reload({ test : true });
// Stop the server
app.stop();
FAQs
Mock JSON Server
The npm package mock-json-server receives a total of 9,683 weekly downloads. As such, mock-json-server popularity was classified as popular.
We found that mock-json-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.