NodeJS

From Wildsong
Jump to navigationJump to search

Stuff I wish I had known a few weeks ago

Useful commands

  • npm version minor - bump the minor version number in package.json and run the preversion, version scripts

I could set a version script to tag git too, that would be useful.

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.