
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.
emocks is a mocking middleware for express servers.
npm install emocks
Assuming we have the following folder structure:
|-- mocks
|-- users
|-- GET.json
|-- :id
|-- PUT.js
|-- server.js
const path = require('path');
const express = require('express');
const emocks = require('emocks');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use('/', emocks(path.join(__dirname, './mocks')));
app.listen(3000);
[
{ "id": 1, "name": "Jon Snow", "state": "Knows nothing" },
{ "id": 2, "name": "Arya Stark", "state": "Knows valar morghulis" }
]
{ "X-Password": "The winter is coming" }
module.exports = function(req, res){
var result = req.body;
result.id = req.params.id;
res.json(result);
}
GET /users
Response
HTTP/1.1 200 OK
X-Password: The winter is coming
[
{ "id": 1, "name": "Jon Snow", "state": "Knows nothing" },
{ "id": 2, "name": "Arya Stark", "state": "Knows valar morghulis" }
]
PUT /users/2
{ "name": "Arya Stark", "state": "Sees nothing" }
Response
{ "id": 2, "name": "Arya Stark", "state": "Sees nothing" }
/**
* @param {string} path - absolute path to mocks directory
* @param {object} options
*/
emocks(path.join(__dirname, './path/to/mocks-folder'), {
//emulate server response delay
delay: 1000,
//custom 'Not Found' handler
404: function(req, res){ ... },
//global headers, will be applied to every response
headers: { "X-Custom-Global-Header": "Hello!" },
});
Please offer suggestions via issues. emocks is an abbreviation for express mocks. Any similarity to emacs is unintended.
FAQs
Mock server based on expressjs
The npm package emocks receives a total of 24 weekly downloads. As such, emocks popularity was classified as not popular.
We found that emocks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
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.