npm

npm ci

Instead of rm -rf node_modules + npm install, you can use npm ci to cleanly install the dependencies in your package-lock.json. It requires a package-lock.json to already exist and will automatically delete the node_modules folder if it's present.

See npm ci | npm Docs for more details.

Creating an npm library