jimsdots

My personalized dotfiles and configs for Windows 10 ⚙️


Project maintained by jimbrig Hosted on GitHub Pages — Theme by mattgraham

Node.js and NPM

Reference

Starred Packages

playball
bower
@google-cloud/secret-manager
googlemaps
@google/markerwithlabel
@googlemaps/markermanager
@googlemaps/markerclustererplus
@googlemaps/js-api-loader
@googlemaps/js-samples
gitmoji-cli
save-local
git-copy-repos-labels-cli
copy-github-labels-cli
firebase-tools
cross-env
pm2
git-labels-cli
git-labels
gist-backup
github-gists-cli
github-gists
nativefier
npm-check-updates
envinfo
fixpack
yarn
webpack
expo-cli
static-marks
@release-it/keep-a-changelog
gulp
release-it
eslint
prettier
jshint
create-react-app
devspace
dbdocs
@dbml/cli

.npmrc

//registry.npmjs.org/:_authToken=<REDEACTED>
bin-links = true
color = "always"
editor = code-insiders
browser = "start"
git = "C:\Program Files\Git\bin\git.exe"
init-author-email = "jimmy.briggs@tychobra.com"
init-author-name = "Jimmy Briggs"
init-author-url = "https://github.com/jimbrig"
init-license = MIT
sign-git-commit = true
sign-git-tag = true

Installation

# chocolatey:
cinst nodejs.install

# scoop
scoop install nodejs

# winget
winget install OpenJS.NodeJS
# install nvm via chocolatey
cinst nvm -y
refreshenv

# verify installation
nvm --version
nvm ls

# install latest version of nodejs/npm
nvm install latest

# list available versions
nvm list available

# declare which version to use
nvm use <version>

# check selected version with node and npm directly
node --version
npm --version

Version Managers

Install nvm-windows, node.js, and npm

There are multiple ways to install Node.js. I recommend using a version manager as versions change very quickly. You will likely need to switch between multiple versions based on the needs of different projects you’re working on.

Node Version Manager, more commonly called nvm, is the most popular way to install multiple versions of Node.js, but is only available for Mac/Linux and not supported on Windows.

Instead, I will walk through the steps to install nvm-windows and then use it to install Node.js and Node Package Manager (npm).

There are alternative version managers to consider as well.

Note about previous installations

It is always recommended to remove any existing installations of Node.js or npm from your operating system before installing a version manager as the different types of installation can lead to strange and confusing conflicts.

This includes deleting any existing nodejs installation directories (e.g., “C:\Program Files\nodejs”) that might remain.

NVM’s generated symlink will not overwrite an existing (even empty) installation directory. For help with removing previous installations, see How to completely remove node.js from Windows.

Other Version Managers

While windows-nvm is currently the most popular version manager for node, there are alternatives to consider:

To install Volta as your version manager (rather than windows-nvm), go to the Windows Installation section of their Getting Started guide, then download and run their Windows installer, following the setup instructions.

You must ensure that Developer Mode is enabled on your Windows machine before installing Volta.

To learn more about using Volta to install multiple versions of Node.js on Windows, see the Volta Docs.

Tips

Packages (nvm)

Stored under the nvm root directory. Defaults to C:/Program Data/nvm. I also have this mirrored under ~.nvm/.

Packages (npm)

prefix Configuration

The prefix config defaults to the location where node is installed. On most systems, this is /usr/local. On Windows, it’s %AppData%\npm. On Unix systems, it’s one level up, since node is typically installed at {prefix}/bin/node rather than {prefix}/node.exe.

When the global flag is set, npm installs things into this prefix. When it is not set, it uses the root of the current package, or the current working directory if not in a package already.

Node Modules

Packages are dropped into the node_modules folder under the prefix. When installing locally, this means that you can require("packagename") to load its main module, or require("packagename/lib/path/to/sub/module") to load other modules.

Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package would place the package in {prefix}/node_modules/@myorg/package. See scope for more details.

If you wish to require() a package, then install it locally.

Global Installation

If the global configuration is set to true, then npm will install packages “globally”.

For global installation, packages are installed roughly the same way, but using the folders described above.

My npm packages

Global:

Stored under %AppData%/npm:

npm install -g dbdocs @dbml/cli expo-cli googlemaps devspace jshint webpack-cli yarn create-react-app envinfo gulp cleave.js prettier release-it @release-it/keep-a-changelog fixpack npm-check-updates static-marks

npm audit fix

npm

npm outdated                 # Show outdated packages
npm ls --depth=0             # List package versions
npm publish --access public  # Publish @scoped package

node-gyp

npm settings (~/.npmrc)

//registry.npmjs.org/:_authToken=<auth_token>

editor = code-insiders
browser = "start"

all = true
global = true

init.author.name = "Jimmy Briggs"
init.author.email = "jimbrig2011@outlook.com"
init.author.url = "https://github.com/jimbrig"
init-license=MIT

sign-git-commit = true

yarn settings

<empty for now>

Semantic Versioning

n - version manager

Install:

curl -L https://git.io/n-install | bash

Commands:

n                    # Output versions installed
n <version>          # Install or activate node <version>
n rm <version ...>   # Remove the given version(s)
n prune              # Remove all versions except the current version

pm2

pm2 start apps.yml                  # load all apps defined in apps.yml
pm2 save                            # save process list
pm2 reload apps.yml [--update-env]  # reload all apps

pm2 list              # list all processes
pm2 monit             # monitor all processes
pm2 describe 0        # display all information about a specific process

pm2 logs [app]        # display logs
pm2 reset [process]   # reset meta data (restarted time...)

pm2 install typescript   # Add Typescript support
pm2 save
npm install -g pm2
pm2 update
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 1M
pm2 set pm2-logrotate:retain 50
pm2 set pm2-logrotate:rotateInterval "0 1 1 1 *"
pm2 set pm2-logrotate:workerInterval 3600

create-react-app

PORT=12345
GENERATE_SOURCEMAP=false
PUBLIC_URL=.               # Build as a local project/file