Example configuration:

{
  "name": "example-basic",
  
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom"
  }
}

Without the run command

Some special commands are special and don’t need npm run COMMAND for the prefix.

$ npm start
$ npm test
$ npm version

You can also run them more verbosely but there is no point.

$ npm run start

Using the run command

Other commands need run.

$ npm run build

Server script

You can leave out specifying start if you want.

Then you need a script at the top-level named server.js - NPM will look for this by name.

You can optionally add the server script to main field to set an entrypoint, but it runs fine without it and it doesn’t seem to work to tell NPM to point at another script.

{
  "name": "example-basic",
  "main": "server.js"
}

Then run:

$ npm start

List

Using run without arguments will list the configured commands.

$ npm run
Lifecycle scripts included in example-basic:
  start
    react-scripts start
  test
    react-scripts test --env=jsdom

available via `npm run-script`:
  build
    react-scripts build
  eject
    react-scripts eject

Note that npm run and npm run-script are equivalent.

Linting

Call a script command using the same target in the command-line as in the package.json file.

$ npm run lint
$ npm run lint:src
{
  "scripts": {
    "lint:src": "eslint src test build",
    "lint": "npm run lint:src && npm run lint:examples",
   }
}

If you need to run a dependency like eslint alone, then use one of these approaches, otherwise the package will not found:

  • NPX
      $ npx eslint --help
    
  • Node modules path.
      $ node_modules/.bin/eslint --help