In Python, I am used to the following two paradigms:
pip freeze > requirements.txt
pip install -r requirements.txt
The first saves a list of requirements to a file, and the second installs them into your environment.
Node has npm install, but I don't get how to I'm supposed to dump the state of my dependencies to a package.json. I Googled and found this:
npm ls | grep -E "^(├|└)─" | cut -d" " -f2 | awk '{FS = "@"; print "\""$1"\"", ":", "\""$2"\""}'
but as the author of this pipeline suggests, there's got to be a better way? What am I missing here?
I just want to dump my current deps into a package.json. As https://npmjs.org/doc/shrinkwrap.html says,
The "package.json" file is still required if you want to use "npm install".
I've skimmed the info on shrinkwrap, but I'm not seeing how to simply accomplish this task with shrinkwrap.
Thanks!
You can create a package.json out of the currently installed package using npm init. Then you can easily move the package.json and simply do npm install to install the packages wherever you want.
This is the closest I got
npm ls | grep -E "^(├|└)─" | cut -d" " -f2 | awk -v quote='"' 'BEGIN { FS = "@" } ; { print quote $1 quote,":",quote $2 quote"," }' | sed -e 's/ :/:/g'
Output is like
"bower": "1.3.12",
"chai": "2.1.2",
"cucumber": "0.4.8",
Still needs to trim the final trailing comma but it's pretty close!