18

Is there a way I can update package.json from node_modules directory? Sometimes I forget to use --save flag.

Thanks!

TLJ
  • 4,525
  • 2
  • 31
  • 46

1 Answers1

25

I came up with this simple cmd

npm install `ls node_modules` --save

It's good enough for my case :-)

TLJ
  • 4,525
  • 2
  • 31
  • 46
  • 1
    In a blank repository if I `npm install --save chalk`, my node_modules folder contains 7 entries (ansi-regex/ ansi-styles/ chalk/ escape-string-regexp/ has-ansi/ strip-ansi/ supports-color/). installing chalk, node-sass and gulp gives 233 packages in the node_modules folder. I am using git bash on windows. – goldenratio Jun 13 '16 at 18:48
  • @goldenratio At the time I was asking(2014), npm would only install the package on top level. All other dependencies of that package would be installed in local node_modules of that package. You can verify that by download node v0.11.14 or so – TLJ Jun 13 '16 at 23:34
  • 2
    Certainly, but for someone stumbling upon this page today, it could be helpful for them to know this will no longer work. – goldenratio Jun 14 '16 at 18:25
  • I just got lots of `npm ERR! registry error parsing json` – Tam Borine Dec 24 '16 at 14:29
  • that may have something to do with npm version. – TLJ Dec 25 '16 at 17:08