npm pre and post scripts

1 min read  •  27 Oct 2022
view-count

In javascript projects, with any script (say something) we can add two more special scripts with prefix pre and post which will basically run before and after the something script.

Let's take an example, here's a minimal project with following package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "presomething": "echo I am happening before something",
    "something": "echo I am doing something",
    "postsomething": "echo I am happening after something"
  },
  "author": "Akul Srivastava",
  "license": "ISC"
}

So here, whenever we run the something script, the presomething script will run before it and the postsomething script will run after it.


something-script-output