NodeJS: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 1: Line 1:
== Stuff I wish I had known a few weeks ago ==
== Stuff I wish I had known a few weeks ago ==
Shortcut to npm docs https://docs.npmjs.com/cli-documentation/misc


=== Useful commands ===
=== Useful commands ===


* npm version minor - bump the minor version number in package.json and run the preversion, version scripts
* npm ls - shows me everything in its tree, there are switches to filter
 
* npm run - shows me what's in package.json scripts
I could set a version script to tag git too, that would be useful.
* npm version minor - bump the minor version number in package.json and '''run git tag ''version''''' (Whoo whoo coolness!!),  run the preversion, version scripts
* npm version patch - bump the patch number instead


=== package.json scripts ===
=== package.json scripts ===

Revision as of 22:22, 28 November 2018

Stuff I wish I had known a few weeks ago

Shortcut to npm docs https://docs.npmjs.com/cli-documentation/misc

Useful commands

  • npm ls - shows me everything in its tree, there are switches to filter
  • npm run - shows me what's in package.json scripts
  • npm version minor - bump the minor version number in package.json and run git tag version (Whoo whoo coolness!!), run the preversion, version scripts
  • npm version patch - bump the patch number instead

package.json scripts

There about 20 predefined, the complete list and what they mean is here. Additionally if that's not enough you can define your own and use npm run scriptname.

I have been using

  • start : I typically use this to run my app in a browser with "start: parcel serve index.html --open"
  • test : should be unit tests, I should really learn how to use unit tests with Node. :-)

I need to learn more about using npm for deployment. I used to use a "build" target to run parcel to build the app for deployment in build/ Then I'd sync the build/ files to the server. Well actually I still do that because I have not learned a better way yet.

Setting a browser

I usually use Chrome on Windows and Firefox on Mac. Instead of wiring a browser into my package.json 'start' command with "--open chrome", I now use just "--open" and let it pick. I can set the browser with

npm config set browser {chrome|firefox|lynx}

Reading docs

npm docs packagename

This jumps to a browser and opens the relevant site for packagename. For example, "npm docs react" opens https://reactjs.org. If you publish your own project as a package then it takes you to the npmjs.com site page.