Skip to main content
Version: 3.10.0

Variant Handlers installation

NPM installation

In order to install a Variant Handler from NPM, first you have to install the correspondent NPM dependency:

npm i --save-dev foo-variant-handler

Configuration file

Once installed, you have to register it in the Mocks Server configuration. You can do it using the configuration file:

const FooVariantHandler = require("foo-variant-handler");

module.exports = {
...config,
variantHandlers: {
register: [FooVariantHandler]
},
};

Using JavaScript config

If you are going to start Mocks Server using the Javascript API, you can also use the programmatic configuration to register your own Variant Handlers:

const { createServer } = require("@mocks-server/main");

const FooVariantHandler = require("./FooVariantHandler");

const server = createServer(
{
variantHandlers: {
register: [FooVariantHandler]
},
},
);

server.start();

Using JavaScript API

You can also use the Javascript API to register your own Variant Handlers from plugins, etc.

core.variantHandlers.register([FooVariantHandler]);