Working with npm scripts

The package.json file contains a field named scripts. This field can contain multiple entries, and each entry is used to create a command. A command can execute any kind of custom logic.

When we create the package.json file using the npm init command, the default command is not implemented:

"scripts": { 
    "test": "echo "Error: no test specified" && exit 1" 
  }, 

In a real-world scenario, we would have multiple commands as in the following example:

{ "name": "repository-name", "version": "1.0.0", "description": "example", "main": "index.html", "scripts": { "start": "node ./src/index.js", "test": "gulp test", "lint": "tslint -c tslint.json ./**/*.ts" }, "repository": { "type": "git", "url": "https://github.com/username/repository-name.git" ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.