
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
An isomorphic fetch utility with first class support for mocking API responses.
An isomorphic fetch utility with first class support for mocking API responses.
// configure it once
import { init } from 'mofetch';
const mocker = init({
baseUrl: 'http://localhost:3000',
mockFetch: true,
});
mocker.get('/api/users', function handler() {
return {
status: 200,
data: [{
id: 1,
name: 'Mocked User 1',
}],
};
});
// use the fetch util in any file
import { fetch } from 'mofetch';
const res = await fetch('/api/users');
const users = await res.json(); // array of users
mofetch and it's peer dependency node-fetch.npm install node-fetch mofetch
Note- You need to provide baseUrl because node-fetch uses absolute urls so we'll call http://localhost:3000/api/todos if you set baseUrl to http://localhost:3000.
mofetch is by default an isomorphic fetch library so you can use it on server and browser both. But when you enable mockFetch: true the fetch function will first check if the url is assigned a mock handler. Based on the handler fetch function returns the data.
Note- If there is no match for API in the mock, fetch will fallback to calling the real API.
400ms is put in API response in development mode (0ms in tests). You can increase the delay by either globally setting the delay.init({
// other options,
delay: 800,
});
or setting it per API mock.
mocker.get(
'/api/todos',
{
status: 200,
data: todos,
},
{
delay: 1000,
},
);
FAQs
An isomorphic fetch utility with first class support for mocking API responses.
The npm package mofetch receives a total of 4 weekly downloads. As such, mofetch popularity was classified as not popular.
We found that mofetch 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.