Node.js: Difference between revisions

From Bitpost wiki
No edit summary
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
Don't mess with anything other than lts, you've been warned:
Don't mess with anything other than lts, you've been warned:
* nvm install --lts
* nvm install --lts
NOTE that you have to reinstall all global packages, as you have a brand new virgin node installation now.
Also, you may want to clean up the older ones at some point.


=== Development ===
=== Development ===


{| class="wikitable"
{| class="wikitable"
! [[Node create a new module]]
! [[Create a new node module]]
|}
|}
{| class="mw-collapsible mw-collapsed wikitable"
{| class="mw-collapsible mw-collapsed wikitable"

Latest revision as of 17:01, 2 March 2023

Installation

Windows

Linux

export NVM_DIR="/home/m/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
  • nvm ls-remote --lts
  • nvm install --lts # to get the latest long-term-support release - you can pick a release too if needed, eg 5.8.0)
  • nvm ls # show what you have
  • nvm alias default stable # needed?
  • the common .bashrc_env should take care of node setup
  • additional fyi goo
    • nvm use 4.2.1; node -v; nvm ls; nvm alias default 0.11.13; nvm use default
    • You can create an .nvmrc file containing version number in the project root directory and it will default to that version
    • Global package install example: npm install -g rad-scripts

Upgrade

Don't mess with anything other than lts, you've been warned:

  • nvm install --lts

NOTE that you have to reinstall all global packages, as you have a brand new virgin node installation now.

Also, you may want to clean up the older ones at some point.

Development

Create a new node module
Register with npm
A one-time registration is required on a new machine if you want to publish from it:
npm adduser
Username: moodboom
Password: (see private)
Email: (this IS public) moodboom@gmail.com
Publish a node module
sudo npm install -g # keep doing this until you are happy with local install
# update version in package.json
# this creates a FULL "annotated" tag, not a "lightweight" tag that doesn't show up for [git describe] - it also removes the need for a separate commit
git tag -a 1.0.5 -m "changes include..."
git push && git push --tags  # NOTE: bitpost has a git hook to push changes all the way up to github
npm publish
Update a node module's dependencies
# make sure dependency in package.json has a carat at the beginning of its version (^x means "at least" version x)
# make sure the dependency has a new version available - completely publish it first if it is your own
# then you can simply reinstall from within the module folder to get all dependencies upgraded
sudo npm install -g
Develop several node modules at once
Convert dependencies to use local packages instead of published versions, eg:
cd ~/development/mah-haus
npm install -S /home/m/development/thedigitalage/rad-scripts

Then reinstall everything (local dependent modules, then parent modules, pita - consider links if doing longer-term dev)

sudo npm install -g

Then convert back to published versions as they become available (it's up to me to stabilize and publish new module versions):

cd ~/development/mah-haus
npm install -S rad-scripts

Troubleshoot

  • After installing a new node version with [nvm install --lts], you'll have to reinstall all node packages. You should be able to run [mh scripts]. Here's what it does:
cdr && npm install -g; cdm && npm install -g; cdas && npm install -g
  • Reinstallation problems

Warning: I had trouble when globally installing rad-scripts from npm and from my local source; for now I'll avoid [npm install -g rad-scripts].

I have also had problems with file locking and permissions when tools like Visual Studio Code are running, see ticket here.

   fixes:
       x close visual studio and kill all node exes (this didn't help this time but has in the past i think?)
       * remove the globally-officially-installed rad-scripts as it blocks installation from the local repo
           rm -rf /home/m/.nvm/versions/node/v8.12.0/lib/node_modules/rad-scripts
           Apparently, we should always use npm install -g from [cdr], not [npm install -g rad-scripts]
           F'in npm.  cmon up your game before yarn etc fragments things into oblivion...
  • If filesystem navigation is slow, loadning npm can be EXTREMELY slow; you can add [ --no-use] to startup, then call [node use] before using it, as a shitty workaround. I'll keep upgrading npm until it is sane. It sure has had a rough growing journey.