You may install this plugin / node module with the following command:
npm install mockserver-node --save-dev
To start or stop the MockServer from any Node.js code you need to import this module using
require('mockserver-node') as follows:
var mockserver = ;
Then you can use either the
stop_mockserver functions as follows:
mockserver;// do somethingmockserver;
The MockServer uses port unification to support HTTP, HTTPS, SOCKS, HTTP CONNECT, Port Forwarding Proxying on the same port. A client can then connect to the single port with both HTTP and HTTPS as the socket will automatically detected SSL traffic and decrypt it when required.
In your project's Gruntfile, add a section named
stop_mockserver to the data object passed into
The following example will result in a both a MockServer and a MockServer Proxy being started on ports
Note: The request log will only be captured in MockServer if the log level is
INFO (or more verbose, i.e.
TRACE) therefore to capture the request log and use the
/retrieve endpoint ensure either the option
trace: true or the command line switch
--verbose is set.
The HTTP, HTTPS, SOCKS and HTTP CONNECT port(s) for both mocking and proxying requests. Port unification is used to support all protocols for proxying and mocking on the same port(s). Supports comma separated list for binding to multiple ports.
Optionally enables port forwarding mode. When specified all requests received will be forwarded to the specified port, unless they match an expectation.
Specified the host to forward all proxy requests to when port forwarding mode has been enabled using the
proxyRemotePort option. This setting is ignored unless
proxyRemotePort has been specified. If no value is provided for
proxyRemotePort has been specified,
proxyRemoteHost will default to
This value specifies the name of the artifact repository host.
This value specifies the path to the artifactory leading to the mockserver-netty jar with dependencies.
This value specifies the artifact version of MockServer to download.
Note: It is also possible to specify a SNAPSHOT version to get the latest unreleased changes.
This value indicates whether the MockServer logs should be written to the console. In addition to logging additional output from the grunt task this options also sets the logging level of the MockServer to INFO. At INFO level all interactions with the MockServer including setting up expectations, matching expectations, clearing expectations and verifying requests are written to the log. The MockServer logs are written to
mockserver.log in the current directory.
Note: It is also possible to use the
--verbose command line switch to enabled verbose level logging from the command line.
This value sets the logging level of the MockServer to TRACE. At TRACE level (in addition to INFO level information) all matcher results, including when specific matchers fail (such as HeaderMatcher) are written to the log. The MockServer logs are written to
mockserver.log in the current directory.
This value indicates whether Java debugging should be enabled and if so which port the debugger should listen on. When this options is provided the following additional option is passed to the JVM:
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + javaDebugPort
suspend=y is used so the MockServer will pause until the debugger is attached. The grunt task will wait 50 seconds for the debugger to be attached before it exits with a failure status.
This value allows any system properties to be passed to the JVM that runs MockServer, for example:
start_mockserver:options:serverPort: 1080jvmOptions: "-Dmockserver.enableCORSForAllResponses=true"
Default value if javaDebugPort is not set:
Default value if javaDebugPort is set:
This value indicates the how many times we will call the check to confirm if the mock server started up correctly. It will default to 110 which will take about 11 seconds to complete, this is normally long enough for the server to startup. The server can take longer to start up if Java debugging is enabled so this will default to 500. The default will, in some cases, need to be overridden as the JVM may take longer to start up on some architectures, e.g. Mac seems to take a little longer.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
All notable and significant changes are detailed in the MockServer changelog
Task submitted by James D Bloom