
Company News
Socket Partners with Replit to Block Malicious Packages in AI-Powered Development
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.
A simple mockserver for testing with nodejs
npm install simulado
# If you have simulado installed gloabally run
simulado
# otherwise
./node_modules/simulado/bin/simulado
You can pass the location of a default mocks json file on startup adding them to Simulado straight away.
simulado --file ./defaultMocks.json
var Simulado = require('simulado');
path is mandatory, without it Simulado will not mock anything.
status defaults to 200 if no status is provided.
headers defaults to {} if no headers are provided.
response will respond with {} if no response is provided, otherwise it will return what you give it.
method defaults to GET if no method is provided. Possible values are GET POST PUT DELETE
timeout defaults to 0 so there will be no delay, accepts seconds. If it's specified, simulado will wait and then send a response.
conditionalRequestHeaders takes an object that reflects the headers sent in the request the mock should respond to
conditionalRequestBody takes an object that reflects the body sent in the request the mock should respond to
The mock will return a promise which will be fulfilled once the Simulado has finished mocking the endpoint.
You may chain requests using then or await the call if you're inside an async function (See https://babeljs.io/docs/plugins/transform-async-to-generator/).
Simulado.mock({
path: '/account/devices',
status: 401,
headers: {"Content-Type": 'application/json'},
response: {
id: 123,
type: "MOBILE",
name: "My work phone"
}
})
Simulado.mock({
path: '/account/*',
status: 200,
headers: {"Content-Type": 'application/json'},
response: {
id: 123,
type: "MOBILE",
name: "My work phone"
}
})
GET localhost.com/account/path-here => OK 200
Simulado.mock({
path: /[^\?]\?username=/,
status: 200,
headers: {"Content-Type": 'application/json'},
response: {
id: 123,
type: "MOBILE",
name: "My work phone"
}
})
Note: Regex are not supported when using a json file. Please consider using plain javascript objects.
If you want to mock out multiple requests at once you can use the mocks function.
The API endpoint for it is /syncMocks
Simulado.mocks([
{
path: '/account/devices',
status: 401,
headers: {"Content-Type": 'application/json'},
response: {
id: 123,
type: "MOBILE",
name: "My work phone"
}
},
{
path: '/interactions/basket',
status: 201,
headers: {"Content-Type": 'application/json'},
response: {
products: [
{id: '1'}
]
}
}
])
You can retrive the request made to an endpoint with Simulado.lastRequest(httpMethod, path)
For instance, using async/await
const lastRequestMade = await Simulado.lastRequest('POST', '/postingPath');
console.log(lastRequestMade.headers); // => {"Content-Type": "application/json"}
console.log(lastRequestMade.body); // => {"name": "simulado"}
// when called with: http://localhost:7000/postingPath?paramName=value
console.log(lastRequestMade.params); // => {"paramName": "value"}
or you can make a request to http://localhost:7000/lastRequest with two headers (method and path), which will respond with the last request as JSON.
Example (using superagent)
superagent.get('http://localhost:7000/lastRequest')
.set('method', 'POST')
.set('path', '/postingPath')
.end(function(_, res) {
var lastRequestMade = res.body;
res.body.headers // => {"paramName": "value"}
});
The old style callbacks are still available on all calls if you prefer to use them, but are now deprecated.
The callback is always the last parameter and will be called once the method has completed or failed.
For instance:
Simulado.lastRequest(function(error, result) {
if (error) {
console.error(error);
} else {
var lastRequestMade = result.body;
console.log(lastRequestMade.headers); // => {"paramName": "value"}
}
});
After mocking, you can call the endpoint whichever way you like. Simulado starts a server on localhost:7001 the path you specify is relative to this.
To inspect all the mocked endpoints you can goto http://localhost:7001/inspect. You can use these enpoints while developing your app by making an API call the http://localhost:7001/[path].
If you want to host simulado on a remote machine, you can require the remote API implementation which allows you to customize the endpoint. Example:
var Simulado = require('simulado/lib/remote-api-impl')({ baseUrl: 'http://simulado.onthecloud.com' });
FAQs
A simple nodejs mockserver
The npm package simulado receives a total of 39 weekly downloads. As such, simulado popularity was classified as not popular.
We found that simulado demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.

Research
/Security News
Newer packages in this compromise use native extensions and .pth loaders to execute JavaScript stealers in developer environments.