Installation
Requires Node.js v22.18+
Option 1: CLI
Create a sample mock in the default directory (./mockaton-mocks)
mkdir -p my-mocks/api
echo "[1,2,3]" > my-mocks/api/foo.GET.200.json
npx mockaton --port 4040 my-mocks
Test it:
curl localhost:4040/api/foo
Option 2: Vite Plugin
npm install mockaton --save-dev
import { defineConfig } from 'vite'
import mockatonPlugin from 'mockaton/vite'
export default defineConfig({
plugins: [
// …other plugins
mockatonPlugin({
port: 4040,
mocksDir: './my-mocks',
})
]
})
Option 3: NPM
npm install mockaton --save-dev
In your package.json:
"scripts": {
"mockaton": "mockaton --port 4040 my-mocks"
}
Option 4: Programmatic Launch
mockaton.config.json is not read by default in this case,
so if you want to use it you’d have to import it.
import { Mockaton } from 'mockaton'
import config from './mockaton.config.js' // optional
const server = await Mockaton(config)
Option 5: Docker
This will spin up Mockaton with the sample directories included in the repository mounted on the container.
git clone https://github.com/ericfortis/mockaton.git --depth 1
cd mockaton
make docker