
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.
Create & Delete RESTful API End-Points dynamically from a deployed the-mock server
The choice is yours:
npm i the-mockyarn add the-mockTo run The-Mock Server successfully, 3 steps need to be handled.
If you already have a MongoDB, skip to the second step. If not:
Important Notes:
config.json fileInside the root project folder create config.json file to link the-mock server with MongoDB and to handle CORS issue by passing response headers.
config.json file contains:
Note: you can copy this config.json, then only change db.url to link to your db.
{
"db": {
"url": "mongodb://localhost:27017/the-mock",
"options": {
"useNewUrlParser": true,
"useUnifiedTopology": true
}
},
"headers": {
"all": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Credentials": true
},
"options": {
"Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE"
}
}
}
server.js fileThe-Mock Server is created using Express JS, thus it needs a starting point to run.
Inside the root project folder create server.js file:
// server.js
const http = require('http');
const theMock = require('the-mock');
const port = process.env.PORT || 3000;
theMock.setConfig('config.json');
const server = http.createServer(theMock);
server.listen(port, () => {
console.log(`The-Mock server is running on Port ${port}`);
console.log(`open your browser on http://localhost:${port}`);
});
then run the-mock server by this commad node server.js.
The-Mock server has a friendly GUI which can easily lead you to create mock end-points.
just navigate to:
To create a Mock Rest Api successfully, 2 steps need to be handled.
The path is all your URL except your domain, paths must be unique. exmaples:
Important Notes:
Basically each path has many resources e.g: GET, POST, PUT, DELETE ..etc,
and to create one click on a specific path. It will navigate you to Resources page.
How to create a resource ? when you click on + sign a box will show up that contains:
Important Notes:
The-Mock server compares request Api call data with the data stored in the-mock database.
If they are EXACTLY EQUAL "===". The-Mock returns a seccessful response, otherwise it returns a failed response.
In other words:
| Request Api Call | The-Mock Stored Data | Response | Reason |
|---|---|---|---|
| path: /api/v1.0/posts method: GET headers: {} | path: /api/v1.0/posts method: GET headers: {} | success | EXACTLY EQUAL "===" |
| path: /api/v1.0/posts/2 method: GET headers: { "authorization": "Bearer blahBlah" } | path: /api/v1.0/posts/1 method: GET headers: { "authorization": "Bearer fake-jwt" } | error | request path should be /posts/1 request headers should be { "authorization": "Bearer fake-jwt" } |
| path: /api/v1.0/posts/2 method: GET headers: { "authorization": "Bearer fake-jwt" } | path: /api/v1.0/posts/2 method: GET headers: { "authorization": "Bearer fake-jwt" } | success | EXACTLY EQUAL "===" |
| path: /api/v1.0/posts method: PUT headers: { "authorization": "Bearer fake-jwt" } body: { "title": "the Mock 1", "content": "the easiest way to mock end-points" } | path: /api/v1.0/posts method: POST headers: { "authorization": "Bearer fake-jwt" } reqBody: { "title": "The Mock", "content": "the easiest way to mock end-points" } | error | request method should be "POST" request body.title should be "The Mock", it's also case-sensitive: t should be T |
| path: /api/v1.0/posts?department=GOV&year=1990 method: GET headers: {} | path: /api/v1.0/posts?department=EDU&year=1992 method: GET headers: {} | error | request path query should be department=EDU&year=1992 |
Code licensed under MIT.
FAQs
Create & Delete RESTful API End-Points dynamically from a deployed the-mock server
The npm package the-mock receives a total of 0 weekly downloads. As such, the-mock popularity was classified as not popular.
We found that the-mock 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.