Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-mock-api-middleware
Advanced tools
Readme
Express middleware for mocking restful APIs
npm install --save-dev express-mock-api-middleware
or
yarn add --dev express-mock-api-middleware
In your server.js
, add the following code
const path = require('path');
const express = require('express');
const app = express();
const mockApiMiddleware = require('express-mock-api-middleware')(
path.resolve(__dirname, 'mock'),
{ ignore: ['asm.js'] }
);
app.use('/', mockApiMiddleware);
const host = 'localhost';
const port = 4000;
app.listen(port, host, error => {
if (error) {
console.error(error);
return;
}
console.info(`http://${host}:${port}`);
});
path.resolve(__dirname, 'mock')
is the folder where mock API files are.
{ ignore: ['asm.js'] }
is the options for more flexible glob. (See how to use ignore
in options)
For example in file /mock/user.js
, you can have content
// you can write your own mock logic here
module.exports = {
'GET /api/user/info': {
id: 101,
userName: 'bob',
email: 'bob@gmail.com',
firstName: 'Bob',
lastName: 'Bushee',
},
'POST /api/user/login': (req, res) => {
const { userName, password } = req.body;
if (userName === 'bob' && password === 'password') {
res.send({
success: true,
});
} else {
res.send({
success: false,
});
}
},
'GET /api/product/:id': (req, res) => {
const { id } = req.params;
res.sendFile(path.join(__dirname, `products/${id}.json`));
}
};
Then you can access the mock API from http://localhost:4000/api/user/info
.
Set the DEBUG
environment variable
DEBUG=mock-api
FAQs
Express middleware for mocking restful APIs
The npm package express-mock-api-middleware receives a total of 588 weekly downloads. As such, express-mock-api-middleware popularity was classified as not popular.
We found that express-mock-api-middleware 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.