Mock Service Worker
  1. Cli
  2. init

init

Places the Service Worker file into a given public directory of your application.

Usage

1$ npx msw init <PUBLIC_DIR>

Where is my "public" directory?

A public directory is usually a root directory of your server (i.e. ./build, ./public, or ./dist). This directory is often committed to Git, and so should be the Mock Service Worker.

Common public directories

Below you can find a list of public directories in most used JavaScript project starters.

Project namePublic directory
Create React App./public
GatsbyJS./static
NextJS./public
VueJS./public
Angular./src (and add it to the assets of the angular.json file)
Preact./src/static
Not sure where is your public directory? Reach out to the maintainers of the development stack that you are using, they should be able to help.