How to keep node_modules in sync with package.json

Today we will be focusing on how to keep our local node_modules up to date whenever the package.json is modified when we pull from remote or switch between branches.

Photo by Thomas Kelley on Unsplash
#/usr/bin/env bash

changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}

check_run package.json "npm install"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store