npm 使用指南

目标:减少nodejs的信息的检索,避免重复造轮子

一、安装

1.yum安装

第一步

curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -

第二步

sudo yum -y install nodejs

如果第二步安装失败,请执行以下命令,然后再执行第二步

sudo yum clean all

如果存在多个 nodesoucre,执行以下命令删除,然后重新执行第一第二步:

sudo rm -fv /etc/yum.repos.d/nodesource*

查看node是否安装成功

node -v
npm -v

2.安装指定版本

(1)清除sudo npm cache clean --force

(1)升级之前需要安装n模块,

sudo npm install -g n

安装n模块后,n -V查看版本

(3)安装指定node版本:

语法格式:n <版本>

(4)安装指定npm版本:

cnpm install npm@7.5.4 -g

二、设置npm源

设置npm源的几种方式
原始源
# the original source
https://registry.npmjs.org/
方案: 使用nrm
安装
npm install -g nrm
列出源的候选项
nrm ls
输出结果:

 https://registry.npmmirror.com/

* npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
  taobao ----- https://registry.npm.taobao.org/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/
使用淘宝源
nrm use taobao
方案: 改变全局的注册
设置成淘宝源
npm config set registry https://registry.npm.taobao.org

设置成开源源

 npm config set registry https://registry.npmmirror.com/
查看结果
npm config get registry
输出结果:

https://registry.npm.taobao.org/
测试一下
npm info underscore
方案: 在命令行里指定源
npm --registry https://registry.npm.taobao.org install [name]
方案: 修改 ~/.npmrc
registry = https://registry.npm.taobao.org
方案: 使用cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install [name]

三、常用指令

1.清楚緩存

npm cache clear & npm cache clear --force

2.其他

npm install 安装模块
npm uninstall 卸载模块
npm update 更新模块
npm outdated 检查模块是否已经过时
npm ls 查看安装的模块
npm init 在项目中引导创建一个package.json文件
npm help 查看某条命令的详细帮助
npm root 查看包的安装路径
npm config 管理npm的配置路径
npm cache 管理模块的缓存
npm start 启动模块
npm stop 停止模块
npm restart 重新启动模块
npm test 测试模块
npm version 查看模块版本
npm view 查看模块的注册信息
npm adduser  用户登录
npm publish 发布模块
npm access 在发布的包上设置访问级别
npm package.json的语法

四、相关使用问题

1. 问题1:

描述:npm ERR! enoent ENOENT: no such file or directory, open '/tmp/pycharm_project_432/superset-frontend/node_modules/src/package.json'

解决:
方法1:
在运行npm start --->无效
方法2:
在运行npm cache clean --force --->无效
方法3:
npm uninstall *。--->解决

2. 问题1:

描述: error  Delete `␍`  prettier/prettier
 superset@0.0.0-dev _lint: `eslint --ignore-path=.eslintignore --ext .js,.jsx,.ts,tsx .

解决:

 方法1: package.json 增加--fix 参数
`eslint --ignore-path=.eslintignore --fix --ext .js,.jsx,.ts,tsx .

原因:是git的一个配置属性:core.autocrlf
  Windows在换行的时候,同时使用了回车符CR(carriage-return character)和换行符LF(linefeed character)
  而Mac和Linux系统,仅仅使用了换行符LF

五、参考文档

- npm 是什么? | npm 中文文档

中国 NPM 镜像

CentOS 使用yum 安装node.js - 小尾学长 - 博客园

【原】npm 常用命令详解 - 白树 - 博客园

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值