npm
导言
Using npm during the batch upload to cloudflare R2.
Introduction¶
npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. It is extremely configurable to support a variety of use cases. Most commonly, you use it to publish, discover, install, and develop node programs.
What is Node
Node.js®
is a JavaScript runtime built on Chrome's V8 JavaScript engine.
- Node.js is an open source server environment;
- Node.js is free;
- Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
options¶
--save-dev
3--save
will install tonode_modules
folder in current dorectory.
execute install path¶
See more in next section
Common Problems¶
node.js version¶
Unsupported engine required: { node: '>=16.17.0' }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '>=16.17.0' },
npm WARN EBADENGINE current: { node: 'v16.15.0', npm: '9.6.6' }
npm WARN EBADENGINE }
Update Node.js with NPM
Using 1
# Install n, Node’s version manager:
npm install -g n
# Install the latest stable version:
$ sudo /staff/shaojiemike/Download/node-v16.15.0-linux-x64/bin/n stable
installing : node-v20.9.0
mkdir : /usr/local/n/versions/node/20.9.0
fetch : https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.xz
copying : node/20.9.0
installed : v20.9.0 (with npm 10.1.0)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r (for bash, zsh, ash, dash, and ksh)
rehash (for csh and tcsh)
apps not found if not using flag --global¶
wrangler not found
$ npm install wrangler --save-dev
$ wrangler
zsh: command not found: wrangler
# shaojiemike @ snode6 in ~ [17:03:56] C:127
$ npm ls
shaojiemike@ /staff/shaojiemike
├── [email protected]
└── [email protected]
npm install path / execute location
To install a public package, on the command line, run npm install <package_name>
. This will create the node_modules
directory in your current directory (if one doesn't exist yet) and will download the package to that directory. (But not link to PATH)2
npx , Link it or Install global
npx <package_name>
to execute local package.
npm install <package_name> -g
will auto-link execute to usr/local/bin