首页 > 编程语言 >NodeJS相关

NodeJS相关

时间:2023-07-26 18:44:50浏览次数:35  
标签:npm ... help NodeJS -- info workspace 相关

全局对象

相比于浏览器中的window全局对象,node的全局对象是global

console.log(window) // window is not defined

例如,你用node执行上面的代码,就会发现浏览器中存在的windownode中并不存在。

在node环境中全局对象为global,在global对象中会存在一些和window对象中同名且作用相同的方法,比如:

global.console.log
global.setInterval
global.clearInterval
global.setTimeout
global.clearTimeout
global.setImmediate

在node环境中声明的变量不会添加到全局对象中,变量声明之后只能在当前文件中使用。(主要是注意,node和浏览器中声明的变量特性有所不同)

var message = 'hello'
console.log(global.message) // undefined

模块包装函数(Module Wrapper Function)

Node是怎么实现模块化的,为什么在模块文件内部定义的变量在模块文件外部不能直接访问到呢?

也就是说,我在一个文件中写过一个cool function,那么我要怎么才能在另一个文件中直接用呢?

  1. 第一种思路,直接原文导入,但是这样就会造成同名的问题,如果a文件中有一个cool function,b文件中也有,那么它不是给我覆盖了吗?
  2. 第二种思路,把它们都进行包装,占用各自的命名空间,除非主动导入,否则不会造成命名污染,这也就是node采用的思路。

其实每一个模块文件中都会有module对象和require方法,也就是说,你并没有发现任何定义它们的地方,但是你可以直接在js文件中用,那么它们是从哪里来的?

在模块文件执行之前,模块文件中的代码会被包裹在模块包装函数当中,这样每个模块中的代码就都有了自己的作用域,所以可以在模块外部就不能访问模块内部的成员了。

(function(exports, require, module, __filename, __dirname){
	// entire module code lives here
})

从这个模块包装函数中可以看到,module和require实际上是模块内部成员,不是全局对象global下面的属性。

__filename:当前模块文件名称。
__dirname:当前文件所在路径。
exports:引用地址指向了module.exports对象,可以理解为是module.exports对象的简写形式。(简单理解就是默认exports = module.exports)

内置模块

path

file system

npm

  • 软件包依赖的相关问题

    • 依赖包存在的位置./node_modules ,并且不止安装了我们主动安装的依赖,还有依赖的依赖,以及依赖的依赖的依赖等,那么如果我们主动安装的两个依赖包,它们各自依赖了同一个依赖包,但是两个依赖的版本却不相同,那怎么办呢?

      解决方法就是:如果后安装的依赖包所依赖的包已经存在,但是版本不同,那么就让这个依赖包自己保存这个依赖包,存在自己的node_modules中。

版本控制

  1. 版本号规范

    Major Version (主要版本):添加新功能,或者破坏了现有的API,如:3.0.0

    Minor Version (次要版本):添加新功能(不会破坏现有的API,在现有的API基础上进行添加),如:3.12.0

    Patch Version (补丁版本):修复了某些bug,如:3.12.23

  2. 版本指定(更新)规则(更新的时候怎么选择,是否更新大版本、次版本)

    ^3.23.2:主要版本不变,更新次要版本和补丁版本;

    ^3.23.2:主要版本和次要版本都不变,仅更新补丁版本;

    3.23.2:也就是使用指定版本,不做任何更新

查看软件包实际版本

我们安装并使用了别人提供的包,怎么查看它们的依赖包呢?或者它们依赖的依赖呢?

  • 方式一:想看谁的就打开谁的package.json文件,看其中的version字段;
  • 方式二:通过npm list 命令查看所有依赖软件包的具体版本,--depth 选项指定查看依赖包的层级。

查看软件包元数据

  • 方式一:在npmjs.com 中查找目标软件包,并查看其元数据;

  • 方式二:通过命令的方式:

    npm view <pkg>
    npm view <pkg> [field]
    
    比如:
    npm view mongoose dist-tags dependencies
    

安装指定版本的软件包

npm i <pkg>@<version>
安装多个软件包可以直接在后面接着写
npm i [email protected] [email protected]

本地安装与全局安装

本地安装:这里的本地安装的本地是指仅安装在当前项目文件夹的node_modules中,也就仅仅能在本项目中使用。默认安装的包都是本地安装,npm i <pkg>

全局安装:安装在node的公共依赖包中,每个项目都可以使用。若要全局安装,需要特地指定,加-g参数。npm i <pkg> -g

查看全局安装包的位置:npm root -g

删除所有的全局安装包:npm un npm-check-updates -g

查看所有的全局安装包:npm list -g --depth 0

查看过期(未更新)的软件包:npm outdated -g

  • nodemon
    • 面临的问题:如果我每次对文件进行了修改都要手动执行一次,才能看到效果,怎么自动执行提高效率呢?
    • 通过nodemon,监控文件变化,自动执行文件
    • npm i nodemon -g
    • nodemon app.js 也就是本该用node的地方,直接用nodemon就行了。
  • npm-check-updates 强制更新
    • npm-check-updates 可以查看应用中有哪些软件包过期了,并进行强制更新(也就是说会忽略前面介绍过的更新规则)

npm的配置

应用场景举例:

​ 由于下载依赖包的网站npmjs.com为国外站点,因为墙的因素,大多数时候下载速度会很慢,怎么解决呢?

​ 通过修改npm的配置,指定更新的源地址为国内的镜像站。

  1. 获取npm的配置

    npm config -l --json

    -l 列表所有默认配置选项

    --json 以json格式显示配置选项

  2. 设置npm配置

    获取npm的下载地址:npm config get registry

    获取npm用户配置文件:npm config get userconfig

  3. 更改npm源地址为国内镜像地址

    npm config set registry https://registry.npm.taobao.org
    npm config set registry https://registry.npmjs.org/
    cat .npmrc
    

npx

npx也是npm软件包提供的命令,它是node平台下的软件包执行器,主要用途有两个:

  1. 避免安装保存软件包,某些工具我们只是临时使用,用完就删掉就行了,也就是一次性使用,用npx就能实现了;
  2. 避免全局软件包版本冲突;
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term> (in a browser)
npm help npm       more involved overview (in a browser)

All commands:

    access          Set access level on published packages

                    Usage:
                    npm access list packages [<user>|<scope>|<scope:team> [<package>]
                    npm access list collaborators [<package> [<user>]]
                    npm access get status [<package>]
                    npm access set status=public|private [<package>]
                    npm access set mfa=none|publish|automation [<package>]
                    npm access grant <read-only|read-write> <scope:team> [<package>]
                    npm access revoke <scope:team> [<package>]

                    Options:
                    [--json] [--otp <otp>] [--registry <registry>]

                    Run "npm help access" for more info

    adduser         Add a registry user account

                    Usage:
                    npm adduser

                    Options:
                    [--registry <registry>] [--scope <@scope>] [--auth-type <legacy|web>]

                    alias: add-user

                    Run "npm help adduser" for more info

    audit           Run a security audit

                    Usage:
                    npm audit [fix|signatures]

                    Options:
                    [--audit-level <info|low|moderate|high|critical|none>] [--dry-run] [-f|--force]
                    [--json] [--package-lock-only]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--foreground-scripts] [--ignore-scripts]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    Run "npm help audit" for more info

    bugs            Report bugs for a package in a web browser

                    Usage:
                    npm bugs [<pkgname> [<pkgname> ...]]

                    Options:
                    [--no-browser|--browser <browser>] [--registry <registry>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    alias: issues

                    Run "npm help bugs" for more info

    cache           Manipulates packages cache

                    Usage:
                    npm cache add <package-spec>
                    npm cache clean [<key>]
                    npm cache ls [<name>@<version>]
                    npm cache verify

                    Options:
                    [--cache <cache>]

                    Run "npm help cache" for more info

    ci              Clean install a project

                    Usage:
                    npm ci

                    Options:
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
                    [--no-bin-links] [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    aliases: clean-install, ic, install-clean, isntall-clean

                    Run "npm help ci" for more info

    completion      Tab Completion for npm

                    Usage:
                    npm completion

                    Run "npm help completion" for more info

    config          Manage the npm configuration files

                    Usage:
                    npm config set <key>=<value> [<key>=<value> ...]
                    npm config get [<key> [<key> ...]]
                    npm config delete <key> [<key> ...]
                    npm config list [--json]
                    npm config edit
                    npm config fix

                    Options:
                    [--json] [-g|--global] [--editor <editor>] [-L|--location <global|user|project>]
                    [-l|--long]

                    alias: c

                    Run "npm help config" for more info

    dedupe          Reduce duplication in the package tree

                    Usage:
                    npm dedupe

                    Options:
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--strict-peer-deps] [--no-package-lock]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
                    [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: ddp

                    Run "npm help dedupe" for more info

    deprecate       Deprecate a version of a package

                    Usage:
                    npm deprecate <package-spec> <message>

                    Options:
                    [--registry <registry>] [--otp <otp>]

                    Run "npm help deprecate" for more info

    diff            The registry diff command

                    Usage:
                    npm diff [...<paths>]

                    Options:
                    [--diff <package-spec> [--diff <package-spec> ...]] [--diff-name-only]
                    [--diff-unified <number>] [--diff-ignore-all-space] [--diff-no-prefix]
                    [--diff-src-prefix <path>] [--diff-dst-prefix <path>] [--diff-text] [-g|--global]
                    [--tag <tag>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    Run "npm help diff" for more info

    dist-tag        Modify package distribution tags

                    Usage:
                    npm dist-tag add <package-spec (with version)> [<tag>]
                    npm dist-tag rm <package-spec> <tag>
                    npm dist-tag ls [<package-spec>]

                    Options:
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    alias: dist-tags

                    Run "npm help dist-tag" for more info

    docs            Open documentation for a package in a web browser

                    Usage:
                    npm docs [<pkgname> [<pkgname> ...]]

                    Options:
                    [--no-browser|--browser <browser>] [--registry <registry>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    alias: home

                    Run "npm help docs" for more info

    doctor          Check your npm environment

                    Usage:
                    npm doctor [ping] [registry] [versions] [environment] [permissions] [cache]

                    Options:
                    [--registry <registry>]

                    Run "npm help doctor" for more info

    edit            Edit an installed package

                    Usage:
                    npm edit <pkg>[/<subpkg>...]

                    Options:
                    [--editor <editor>]

                    Run "npm help edit" for more info

    exec            Run a command from a local or remote npm package

                    Usage:
                    npm exec -- <pkg>[@<version>] [args...]
                    npm exec --package=<pkg>[@<version>] -- <cmd> [args...]
                    npm exec -c '<cmd> [args...]'
                    npm exec --package=foo -c '<cmd> [args...]'

                    Options:
                    [--package <package-spec> [--package <package-spec> ...]] [-c|--call <call>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    alias: x

                    Run "npm help exec" for more info

    explain         Explain installed packages

                    Usage:
                    npm explain <package-spec>

                    Options:
                    [--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]

                    alias: why

                    Run "npm help explain" for more info

    explore         Browse an installed package

                    Usage:
                    npm explore <pkg> [ -- <command>]

                    Options:
                    [--shell <shell>]

                    Run "npm help explore" for more info

    find-dupes      Find duplication in the package tree

                    Usage:
                    npm find-dupes

                    Options:
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--strict-peer-deps] [--no-package-lock]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
                    [--no-audit] [--no-bin-links] [--no-fund]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    Run "npm help find-dupes" for more info

    fund            Retrieve funding information

                    Usage:
                    npm fund [<package-spec>]

                    Options:
                    [--json] [--no-browser|--browser <browser>] [--no-unicode]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [--which <fundingSourceNumber>]

                    Run "npm help fund" for more info

    get             Get a value from the npm configuration

                    Usage:
                    npm get [<key> ...] (See `npm config`)

                    Options:
                    [-l|--long]

                    Run "npm help get" for more info

    help            Get help on npm

                    Usage:
                    npm help <term> [<terms..>]

                    Options:
                    [--viewer <viewer>]

                    alias: hlep

                    Run "npm help help" for more info

    help-search     Search npm help documentation

                    Usage:
                    npm help-search <text>

                    Options:
                    [-l|--long]

                    Run "npm help help-search" for more info

    hook            Manage registry hooks

                    Usage:
                    npm hook add <pkg> <url> <secret> [--type=<type>]
                    npm hook ls [pkg]
                    npm hook rm <id>
                    npm hook update <id> <url> <secret>

                    Options:
                    [--registry <registry>] [--otp <otp>]

                    Run "npm help hook" for more info

    init            Create a package.json file

                    Usage:
                    npm init <package-spec> (same as `npx <package-spec>`)
                    npm init <@scope> (same as `npx <@scope>/create`)

                    Options:
                    [-y|--yes] [-f|--force] [--scope <@scope>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--no-workspaces-update] [--include-workspace-root]

                    aliases: create, innit

                    Run "npm help init" for more info

    install         Install a package

                    Usage:
                    npm install [<package-spec> ...]

                    Options:
                    [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
                    [-E|--save-exact] [-g|--global]
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
                    [--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
                    [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall

                    Run "npm help install" for more info

    install-ci-test Install a project with a clean slate and run tests

                    Usage:
                    npm install-ci-test

                    Options:
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
                    [--no-bin-links] [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    aliases: cit, clean-install-test, sit

                    Run "npm help install-ci-test" for more info

    install-test    Install package(s) and run tests

                    Usage:
                    npm install-test [<package-spec> ...]

                    Options:
                    [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
                    [-E|--save-exact] [-g|--global]
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--strict-peer-deps] [--prefer-dedupe] [--no-package-lock] [--package-lock-only]
                    [--foreground-scripts] [--ignore-scripts] [--no-audit] [--no-bin-links]
                    [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: it

                    Run "npm help install-test" for more info

    link            Symlink a package folder

                    Usage:
                    npm link [<package-spec>]

                    Options:
                    [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
                    [-E|--save-exact] [-g|--global]
                    [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
                    [--global-style] [--strict-peer-deps] [--no-package-lock]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
                    [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: ln

                    Run "npm help link" for more info

    ll              List installed packages

                    Usage:
                    npm ll [[<@scope>/]<pkg> ...]

                    Options:
                    [-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
                    [--package-lock-only] [--no-unicode]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: la

                    Run "npm help ll" for more info

    login           Login to a registry user account

                    Usage:
                    npm login

                    Options:
                    [--registry <registry>] [--scope <@scope>] [--auth-type <legacy|web>]

                    Run "npm help login" for more info

    logout          Log out of the registry

                    Usage:
                    npm logout

                    Options:
                    [--registry <registry>] [--scope <@scope>]

                    Run "npm help logout" for more info

    ls              List installed packages

                    Usage:
                    npm ls <package-spec>

                    Options:
                    [-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
                    [--package-lock-only] [--no-unicode]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: list

                    Run "npm help ls" for more info

    org             Manage orgs

                    Usage:
                    npm org set orgname username [developer | admin | owner]
                    npm org rm orgname username
                    npm org ls orgname [<username>]

                    Options:
                    [--registry <registry>] [--otp <otp>] [--json] [-p|--parseable]

                    alias: ogr

                    Run "npm help org" for more info

    outdated        Check for outdated packages

                    Usage:
                    npm outdated [<package-spec> ...]

                    Options:
                    [-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]

                    Run "npm help outdated" for more info

    owner           Manage package owners

                    Usage:
                    npm owner add <user> <package-spec>
                    npm owner rm <user> <package-spec>
                    npm owner ls <package-spec>

                    Options:
                    [--registry <registry>] [--otp <otp>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces]

                    alias: author

                    Run "npm help owner" for more info

    pack            Create a tarball from a package

                    Usage:
                    npm pack <package-spec>

                    Options:
                    [--dry-run] [--json] [--pack-destination <pack-destination>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    Run "npm help pack" for more info

    ping            Ping npm registry

                    Usage:
                    npm ping

                    Options:
                    [--registry <registry>]

                    Run "npm help ping" for more info

    pkg             Manages your package.json

                    Usage:
                    npm pkg set <key>=<value> [<key>=<value> ...]
                    npm pkg get [<key> [<key> ...]]
                    npm pkg delete <key> [<key> ...]
                    npm pkg set [<array>[<index>].<key>=<value> ...]
                    npm pkg set [<array>[].<key>=<value> ...]
                    npm pkg fix

                    Options:
                    [-f|--force] [--json]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces]

                    Run "npm help pkg" for more info

    prefix          Display prefix

                    Usage:
                    npm prefix [-g]

                    Options:
                    [-g|--global]

                    Run "npm help prefix" for more info

    profile         Change settings on your registry profile

                    Usage:
                    npm profile enable-2fa [auth-only|auth-and-writes]
                    npm profile disable-2fa
                    npm profile get [<key>]
                    npm profile set <key> <value>

                    Options:
                    [--registry <registry>] [--json] [-p|--parseable] [--otp <otp>]

                    Run "npm help profile" for more info

    prune           Remove extraneous packages

                    Usage:
                    npm prune [[<@scope>/]<pkg>...]

                    Options:
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--dry-run]
                    [--json] [--foreground-scripts] [--ignore-scripts]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    Run "npm help prune" for more info

    publish         Publish a package

                    Usage:
                    npm publish <package-spec>

                    Options:
                    [--tag <tag>] [--access <restricted|public>] [--dry-run] [--otp <otp>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]
                    [--provenance|--provenance-file <file>]

                    Run "npm help publish" for more info

    query           Retrieve a filtered list of packages

                    Usage:
                    npm query <selector>

                    Options:
                    [-g|--global]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    Run "npm help query" for more info

    rebuild         Rebuild a package

                    Usage:
                    npm rebuild [<package-spec>] ...]

                    Options:
                    [-g|--global] [--no-bin-links] [--foreground-scripts] [--ignore-scripts]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    alias: rb

                    Run "npm help rebuild" for more info

    repo            Open package repository page in the browser

                    Usage:
                    npm repo [<pkgname> [<pkgname> ...]]

                    Options:
                    [--no-browser|--browser <browser>] [--registry <registry>]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    Run "npm help repo" for more info

    restart         Restart a package

                    Usage:
                    npm restart [-- <args>]

                    Options:
                    [--ignore-scripts] [--script-shell <script-shell>]

                    Run "npm help restart" for more info

    root            Display npm root

                    Usage:
                    npm root

                    Options:
                    [-g|--global]

                    Run "npm help root" for more info

    run-script      Run arbitrary package scripts

                    Usage:
                    npm run-script <command> [-- <args>]

                    Options:
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--if-present] [--ignore-scripts]
                    [--foreground-scripts] [--script-shell <script-shell>]

                    aliases: run, rum, urn

                    Run "npm help run-script" for more info

    search          Search for packages

                    Usage:
                    npm search [search terms ...]

                    Options:
                    [-l|--long] [--json] [--color|--no-color|--color always] [-p|--parseable]
                    [--no-description] [--searchopts <searchopts>] [--searchexclude <searchexclude>]
                    [--registry <registry>] [--prefer-online] [--prefer-offline] [--offline]

                    aliases: find, s, se

                    Run "npm help search" for more info

    set             Set a value in the npm configuration

                    Usage:
                    npm set <key>=<value> [<key>=<value> ...] (See `npm config`)

                    Options:
                    [-g|--global] [-L|--location <global|user|project>]

                    Run "npm help set" for more info

    shrinkwrap      Lock down dependency versions for publication

                    Usage:
                    npm shrinkwrap

                    Run "npm help shrinkwrap" for more info

    star            Mark your favorite packages

                    Usage:
                    npm star [<package-spec>...]

                    Options:
                    [--registry <registry>] [--no-unicode] [--otp <otp>]

                    Run "npm help star" for more info

    stars           View packages marked as favorites

                    Usage:
                    npm stars [<user>]

                    Options:
                    [--registry <registry>]

                    Run "npm help stars" for more info

    start           Start a package

                    Usage:
                    npm start [-- <args>]

                    Options:
                    [--ignore-scripts] [--script-shell <script-shell>]

                    Run "npm help start" for more info

    stop            Stop a package

                    Usage:
                    npm stop [-- <args>]

                    Options:
                    [--ignore-scripts] [--script-shell <script-shell>]

                    Run "npm help stop" for more info

    team            Manage organization teams and team memberships

                    Usage:
                    npm team create <scope:team> [--otp <otpcode>]
                    npm team destroy <scope:team> [--otp <otpcode>]
                    npm team add <scope:team> <user> [--otp <otpcode>]
                    npm team rm <scope:team> <user> [--otp <otpcode>]
                    npm team ls <scope>|<scope:team>

                    Options:
                    [--registry <registry>] [--otp <otp>] [-p|--parseable] [--json]

                    Run "npm help team" for more info

    test            Test a package

                    Usage:
                    npm test [-- <args>]

                    Options:
                    [--ignore-scripts] [--script-shell <script-shell>]

                    aliases: tst, t

                    Run "npm help test" for more info

    token           Manage your authentication tokens

                    Usage:
                    npm token list
                    npm token revoke <id|token>
                    npm token create [--read-only] [--cidr=list]

                    Options:
                    [--read-only] [--cidr <cidr> [--cidr <cidr> ...]] [--registry <registry>]
                    [--otp <otp>]

                    Run "npm help token" for more info

    uninstall       Remove a package

                    Usage:
                    npm uninstall [<@scope>/]<pkg>...

                    Options:
                    [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
                    [-g|--global]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    aliases: unlink, remove, rm, r, un

                    Run "npm help uninstall" for more info

    unpublish       Remove a package from the registry

                    Usage:
                    npm unpublish [<package-spec>]

                    Options:
                    [--dry-run] [-f|--force]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces]

                    Run "npm help unpublish" for more info

    unstar          Remove an item from your favorite packages

                    Usage:
                    npm unstar [<package-spec>...]

                    Options:
                    [--registry <registry>] [--no-unicode] [--otp <otp>]

                    Run "npm help unstar" for more info

    update          Update packages

                    Usage:
                    npm update [<pkg>...]

                    Options:
                    [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
                    [-g|--global] [--install-strategy <hoisted|nested|shallow|linked>]
                    [--legacy-bundling] [--global-style]
                    [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
                    [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
                    [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root] [--install-links]

                    aliases: up, upgrade, udpate

                    Run "npm help update" for more info

    version         Bump a package version

                    Usage:
                    npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]

                    Options:
                    [--allow-same-version] [--no-commit-hooks] [--no-git-tag-version] [--json]
                    [--preid prerelease-id] [--sign-git-tag]
                    [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--no-workspaces-update] [--include-workspace-root]

                    alias: verison

                    Run "npm help version" for more info

    view            View registry info

                    Usage:
                    npm view [<package-spec>] [<field>[.subfield]...]

                    Options:
                    [--json] [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
                    [-ws|--workspaces] [--include-workspace-root]

                    aliases: info, show, v

                    Run "npm help view" for more info

    whoami          Display npm username

                    Usage:
                    npm whoami

                    Options:
                    [--registry <registry>]

                    Run "npm help whoami" for more info

Specify configs in the ini-formatted file:
    F:\Users\Sher10ck\.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

[email protected]

模块查找规则

先回答两个问题:谁查找模块,查找什么模块

  • 当然是代码中表明了引用,一般是require
  • 查找的当然是指定的模块(包),也就是require()中传入的参数

那么有两种情况:

  • 指定了查找路径

    require("./cool_package")
    

    默认为引用的是自己编写的文件

    1. 查找cool_package.js
    2. 查找cool_package.json
    3. 查找cool_package文件夹,查看入口文件(package.json->main)
    4. 查找cool_package文件夹中的index.js文件
  • 未指定查找路径

    require('cool_package')
    

    默认为引用的是依赖包

    path:[
        '/Users/administrators/Desktop/Node/code/node_modules',
        '/Users/administrators/Desktop/Node/node_modules',
        '/Users/administrators/Desktop/node_modules',
        '/Users/administrators/node_modules',
        '/Users/node_modules',
        '/node_modules',
    ]
    

标签:npm,...,help,NodeJS,--,info,workspace,相关
From: https://www.cnblogs.com/sherlock-V/p/17583298.html

相关文章

  • oracle查询相关性能语句
    ------------------------------SGA-----------------------------------------------SGA各部分大小showsgaselect*fromv$sga;SELECT*FROMV$SGAINFO;--SGA设置大小showparametersga_target--SGA各个池大小COLnameFORMATa32;SELECTpool,name,bytes/1024......
  • js校验IPv4/IPv6/域名/url等相关正则
    /***域名校验eg:www.baidu.com*@param{*}val需要校验的值*/exportfunctionisDomain(val){constreg=/^([0-9a-zA-Z-]{1,}\.)+([a-zA-Z]{2,})$/;returnreg.test(val);}/***ipv4校验eg:10.0.0.1*@param{*}val需要校验的值*/exportfunc......
  • 算法学习--并查集相关知识及例题
    一、并查集的定义二、基本操作1、初始化一开始,每个元素都是独立的集合#include<iostream>usingnamespacestd;constintmaxN=1000;intfather[maxN];intmain(){for(inti=1;i<=maxN;i++){father[i]=i;}return0;}2、查找递推版本://返......
  • Tita 升级|「绩效」相关功能优化升级
    1.完成值录入节点支持批量导入完成值Tita-OKR和新绩效一体化管理平台点击批量导入按钮,下载列表数据,完成填写后导入2.考核模板流程设置中支持添加多个绩效面谈节点,且能自定义控制绩效面谈的节点顺序使用场景:当考核执行时,需要和多个角色进行面谈a.前往考核模板中的考核流......
  • 28号支架相关
    主题:两种把数据分割的方式:“字符串输入”以及“json输入”“pycharm中相同代码段的同时高亮”的实现效果高亮首先介绍如何实现下图效果,动作是“双击某字段,整页中与其相同的各处都会高亮”:在设置的插件市场下载并应用插件“BrowseWordCaret”:​ 按下图示步骤:......
  • 反射 p5 反射相关使用和暴破
    反射相关使用和暴破通过反射创建对象方式一:调用类中的public修饰的无参构造器;方式二:调用类中的指定构造器;Class类相关方法:newInstance():调用类中的无参构造器,获取对应类的对象;getConstructor(Class...clazz):根据参数列表,获取对应的public构造器对象;getDecalaredConstruct......
  • iptables——相关概念
    本系列文章参考朱双印博客,原文链接:https://www.zsythink.net/archives/1199写在前面设置iptables防火墙,需要明确的2点:1.本机开通了哪些服务端口2.有哪些机器需要访问本机一般为了安全性考虑,先只开通需要本机对需要访问本机的22端口和本机的服务端口。#阻止所有流量iptable......
  • 赛维1325雕刻机系统安装和相关支持软件
    “赛维”牌雕刻机是行业内较为知名的cnc数控品牌。因工作原因,我公司也购买了一台sw1325雕刻机,其实是买错了,根据台面大小来看,1318.1312都可以买。买这个雕刻机主要用于切割本公司亚克力面板的切割使用。但官方原本留的售后联系方式服务并不理想。后又联系该公司张工,获得了一个比较......
  • Ubuntu中iptables的相关操作命令
    iptables简介:Iptables和UFW (UncomplicatedFirewall)都是Linux操作系统中常用的防火墙管理工具,它们的主要区别如下:相同点:两者都是Linux操作系统中的防火墙管理工具,可以配置网络规则以限制网络流量。工作原理:iptables和UFW都基于netfilter框架来实现防火墙功能。......
  • 使用 MyBatis 相关依赖包(20230725)
    开发SpringBoot应用时使用MyBatis的相关依赖包…… 说明:本文首次发布于2023-7-2510点(北京时间),其中的“最新”是这个时间点最新。 0、序章梳理开发SpringBoot项目时,使用各种MyBatis相关依赖包的版本及其关系。 1、SpringBoot2.7.13默认MyBatisFramewo......