title | description | keywords | author | marp | theme | _header | _footer |
---|---|---|---|---|---|---|---|
NPM Tools |
A short introduction to a collection of useful node packages for everyday use. |
npm,tool,package,version |
Marcel Eichner |
true |
marceleichner |
2022-03-16 |
⚒️ nvm
nvm is a version manager for node.js
nvm allows you to quickly install and use different versions of node via the command line on all major operating systems
- POSIX-compliant shell: sh, dash, ksh, zsh, bash
- platforms: unix, macOS, and windows WSL
- simply install/uninstall node version(s)
- have multiple node versions installed
- pin node version used in project by adding a
.nvmrc
🐕 husky
"modern native git hooks made easy" – Easily setup local git commit hooks for the whole team.
- Run custom script(s) every time an action occurs (f.e. "commit", "push")
- use cases:
- lint file(s)
- auto-format file(s)
- run test(s)
- build files
- generate types
- validate format of commit-message
Install the dependency:
npm install husky --save-dev;
Set the "prepare" script in package.json
, install git-hooks:
npm set-script prepare "husky install"
npm run prepare
This will also create .husky
directory and add it to .gitignore
.
Run a script everytime new code is pushed to a remote with the pre-push
action:
npx husky add .husky/pre-push "npm lint"
git add .husky/pre-push
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# <insert lint command here>
Sometimes scripts are slow and must be bypassed:
git commit --no-verify -m "chore: my message"
⬆️ npm-check
"Check for outdated, incorrect, and unused dependencies." - Interactive way of updating npm packages
- get an overview of the up-to-date "state" of dependencies
- visually appealing, F+STRG simple way of updating multiple packages
- see different types of updates: patch, minor, major
- find extranous packages
- find missing packages
"upgrades your package.json dependencies to the latest versions" - ignoring specified versions
- ignore major (breaking) and minor updates:
npx npm-check-update --target minor
- run tests while updating
npx npm-check-update --doctor
📦 depcheck
Analyze dependencies in a project and find unused and useless dependencies.
- ideal for integration into CI
- detect packages that have been added by mistake
- detect packages which are not actually used (anymore)
Some dependencies are not required in the sources but are used for compilation, linting and other tasks. Those packages often are detected and are false-positives and can be ignore while also documenting why they are added:
# .depcheck.yml
# use `npx depcheck --config .depcheck.yml`
ignores:
# required by ngx-bootstrap
- "bootstrap"
# used for git hooks
- "husky"
🪣 modclean
"Remove unwanted files and directories from your node_modules folder"
Collection of different glob-patterns & filters to remove files from node_modules which are not used.
- reduce size of packaged applications (electron)
- reduce size of docker image
- in CI reduce space used for cache(s)
- save space on machine
- Example Benchmarks
"Easily find and remove old and heavy node_modules folders ✨"
"Ever needed to see all the license info for a module and its dependencies?"
-
extract SPDX identifiers of packages
-
list licenses for legal auditing, documentation:
npx license-checker-rseidelsohn --csv --out /path/to/licenses.csv
-
check if packages added with unwanted licenses
npx license-checker-rseidelsohn --failOn 'GPL'
- check packages in
package.json
files of projects that you’re using to find new inspiring helpful tools. - check github explore: https://github.com/topics/javascript
- check node weekly newsletter