Avoiding global installs (npm install -g
) can help maintain consistency among project collaborators and prevent the need for lengthy guides on setting up projects locally.
Regarding the "bin config," it is important to note that this section in the package.json file is used to specify commands exported by your project, not commands used by your app itself. For example, the bin section in package.json for a CLI application like gulp
looks like:
"bin": {
"gulp": "./bin/gulp.js"
},
Dependencies needed by your application should be added to the devDependencies
section to ensure everyone working on the project uses the same versions of tools like gulp
or tsc
.
Using npx
instead of global installs allows you to specify project-specific dependencies in devDependencies
, ensuring consistent tool usage. Creating aliases for common command line tools as suggested by @machineghost can further streamline development workflows. In cases where the command name differs from the package name, an alias like:
alias tsc='npx --package=typescript tsc'
can be helpful. While npx
typically prompts installation if a version is not found in the current project, adding the "--yes" flag can automate this process for a more seamless experience:
alias command=`npx -y gulp`
This approach will use the specified version in the project if available, but automatically install and run it if necessary.