Copy the worker script into the given directory.


npx msw init <PUBLIC_DIR> [options]



A relative path to the public directory of your application.

For example, when using NextJS, the public directory is located in /public, and that’s the path you should provide to this command:

npx msw init ./public



Save the given PUBLIC_DIR in package.json for future automatic updates of the worker script.

npx msw init ./public --save

Running this command will save the ./public directory in your package.json:

// package.json
  "name": "my-app",
  "msw": {
    "workerDirectory": "./public"

If this property is present, whenever you install the msw package, the worker script will be copied to the msw.workerDirectory destination automatically. This ensures the worker script being in sync with the currently installed version of the library.

Managing the worker

Learn how to manage the worker script updates.