跳转至

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

  1. --save-dev 3
  2. --save will install to node_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

  # shaojiemike @ snode6 in ~ [17:51:17]
  $ l node_modules/wrangler/bin/wrangler.js
  -rwxr-xr-x 1 shaojiemike acsastaff 4.1K Nov  1 16:33 node_modules/wrangler/bin/wrangler.js

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

  $ sudo npm install wrangler --save-dev -g
  $ l `which wrangler`
  lrwxrwxrwx 1 root root 44 Nov  1 17:36 /usr/local/bin/wrangler -> ../lib/node_modules/wrangler/bin/wrangler.js

参考文献

评论