{"id":18724347,"url":"https://github.com/mock-server/mockserver-node","last_synced_at":"2025-04-06T21:16:26.279Z","repository":{"id":22680032,"uuid":"97018273","full_name":"mock-server/mockserver-node","owner":"mock-server","description":"Node.js module and grunt plugin to start and stop MockServer and MockServer Proxy","archived":false,"fork":false,"pushed_at":"2024-03-15T16:02:10.000Z","size":1914,"stargazers_count":41,"open_issues_count":11,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T12:08:03.103Z","etag":null,"topics":["grunt-plugin","java-client","javascript-client","mock-server","node-client","node-module","proxy","ruby-client"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mock-server.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-12T14:36:41.000Z","updated_at":"2024-06-18T14:07:18.428Z","dependencies_parsed_at":"2024-06-18T14:07:01.994Z","dependency_job_id":"228f7df7-6659-4fbd-9ff8-12333796ba6d","html_url":"https://github.com/mock-server/mockserver-node","commit_stats":{"total_commits":282,"total_committers":20,"mean_commits":14.1,"dds":0.5638297872340425,"last_synced_commit":"194181516709fe8567a965b5de92f73bdf7ac78b"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mock-server","download_url":"https://codeload.github.com/mock-server/mockserver-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550693,"owners_count":20956987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grunt-plugin","java-client","javascript-client","mock-server","node-client","node-module","proxy","ruby-client"],"created_at":"2024-11-07T14:06:10.694Z","updated_at":"2025-04-06T21:16:26.261Z","avatar_url":"https://github.com/mock-server.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mockserver-node \n\n\u003e Node module and grunt plugin to start and stop [MockServer](http://mock-server.com/) and [MockServer](http://mock-server.com/) proxy\n\n[![Build status](https://badge.buildkite.com/84d4f1ca00ee6639c1825ea31f0dcd50bd73088571813a219b.svg?style=square\u0026theme=slack)](https://buildkite.com/mockserver/mockserver-node) [![Dependency Status](https://david-dm.org/mock-server/mockserver-node.png)](https://david-dm.org/mock-server/mockserver-node) [![devDependency Status](https://david-dm.org/mock-server/mockserver-node/dev-status.png)](https://david-dm.org/mock-server/mockserver-node#info=devDependencies)\n\n[![NPM](https://nodei.co/npm/mockserver-node.png?downloads=true\u0026stars=true)](https://nodei.co/npm/mockserver-node/) \n\n# Community\n\n* Backlog:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://trello.com/b/dsfTCP46/mockserver\" target=\"_blank\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/trello_badge-md.png\" alt=\"Trello Backlog\"\u003e\u003c/a\u003e\n* Freature Requests:\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/mock-server/mockserver/issues\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/GitHub_Logo-md.png\" alt=\"Github Issues\"\u003e\u003c/a\u003e\n* Issues / Bugs:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/mock-server/mockserver/issues\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/GitHub_Logo-md.png\" alt=\"Github Issues\"\u003e\u003c/a\u003e\n* Chat:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://join-mock-server-slack.herokuapp.com\" target=\"_blank\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/slack-logo-slim-md.png\" alt=\"Join Slack\"\u003e\u003c/a\u003e\n\n## Getting Started\n\nThis node module can be used to start and stop [MockServer](http://mock-server.com/) and the [MockServer](http://mock-server.com/) proxy as a node module or as a Grunt plugin.  More information about the [MockServer](http://mock-server.com/) can be found at [mock-server.com](http://mock-server.com/). \n\nYou may install this plugin / node module with the following command:\n\n```shell\nnpm install mockserver-node --save-dev\n```\n\n## Node Module\n\nTo start or stop the MockServer from any Node.js code you need to import this module using `require('mockserver-node')` as follows:\n\n```js\nvar mockserver = require('mockserver-node');\n```\n\nThen you can use either the `start_mockserver` or `stop_mockserver` functions as follows:\n\n```js\nmockserver.start_mockserver({\n                serverPort: 1080,\n                trace: true\n            });\n\n// do something\n\nmockserver.stop_mockserver({\n                serverPort: 1080\n            });\n```\n\nThe 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.\n\n## Grunt Plugin\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.\n\nIn your project's Gruntfile, add a section named `start_mockserver` and `stop_mockserver` to the data object passed into `grunt.initConfig()`.\n\nThe following example will result in a both a MockServer and a MockServer Proxy being started on ports `1080` and `1090`.\n\n```js\ngrunt.initConfig({\n    start_mockserver: {\n        options: {\n            serverPort: 1080,\n            trace: true\n        }\n    },\n    stop_mockserver: {\n        options: {\n            serverPort: 1080\n        }\n    }\n});\n\ngrunt.loadNpmTasks('mockserver-node');\n```\n\n## Request Log\n\n**Note:** The request log will only be captured in MockServer if the log level is `INFO` (or more verbose, i.e. `DEBUG` or `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.\n\n### Options\n\n#### options.serverPort\nType: `Integer`\nDefault value: `undefined`\n\nThe 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.\n\n#### options.proxyRemotePort\nType: `Integer`\nDefault value: `undefined` \n\nOptionally enables port forwarding mode. When specified all requests received will be forwarded to the specified port, unless they match an expectation.\n\n#### options.proxyRemoteHost\nType: `String`\nDefault value: `undefined`  \n\nSpecified 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 `proxyRemoteHost` when `proxyRemotePort` has been specified, `proxyRemoteHost` will default to `\"localhost\"`.\n\n#### options.artifactoryHost\nType: `String` \nDefault value: `oss.sonatype.org`\n\nThis value specifies the name of the artifact repository host.\n\n#### options.artifactoryPath\nType: `String` \nDefault value: `/content/repositories/releases/org/mock-server/mockserver-netty/`\n\nThis value specifies the path to the artifactory leading to the mockserver-netty jar with dependencies.\n\n#### options.mockServerVersion\nType: `String` \nDefault value: `5.15.0`\n\nThis value specifies the artifact version of MockServer to download.\n\n**Note:** It is also possible to specify a SNAPSHOT version to get the latest unreleased changes.\n\n#### options.verbose\nType: `Boolean`\nDefault value: `false`\n\nThis 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 [**DEBUG**](http://www.mock-server.com/mock_server/debugging_issues.html). At **DEBUG** 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.  \n\n**Note:** It is also possible to use the ```--verbose``` command line switch to enabled verbose level logging from the command line.\n\n#### options.trace\nType: `Boolean`\nDefault value: `false`\n\nThis value sets the logging level of the MockServer to [**TRACE**](http://www.mock-server.com/mock_server/debugging_issues.html). 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. \n\n#### options.javaDebugPort\nType: `Integer`\nDefault value: `undefined`\n\nThis 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:\n \n```bash\n\"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=\" + javaDebugPort\n```  \n\nNote that `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.\n  \n#### options.jvmOptions\nType: `String`\nDefault value: `undefined`\n\nThis value allows any system properties to be passed to the JVM that runs MockServer, for example:\n \n```js\nstart_mockserver: {\n    options: {\n        serverPort: 1080,\n        jvmOptions: \"-Dmockserver.enableCORSForAllResponses=true\"\n    }\n}\n```  \n\n#### options.startupRetries\nType: `Integer`\nDefault value if javaDebugPort is not set: `110`\nDefault value if javaDebugPort is set: `500`\n\nThis 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.\n\n## Contributing\nIn 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](http://gruntjs.com/).\n\n## Changelog\n\nAll notable and significant changes are detailed in the [MockServer changelog](https://github.com/mock-server/mockserver/blob/master/changelog.md) \n\n---\n\nTask submitted by [James D Bloom](http://blog.jamesdbloom.com)\n\n[![Analytics](https://ga-beacon.appspot.com/UA-32687194-4/mockserver-node/README.md)](https://github.com/igrigorik/ga-beacon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmock-server%2Fmockserver-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmock-server%2Fmockserver-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmock-server%2Fmockserver-node/lists"}