Nodejs项目包发布

一、安装node和npm

下载nodejs压缩包

$ wget https://nodejs.org/download/release/v14.21.3/node-v14.21.3-linux-x64.tar.gz

解压nodejs压缩包

$ tar -xzvf node-v14.21.3-linux-x64.tar.gz && cd node-v14.21.3-linux-x64/

为node和npm创建软链接

$ sudo ln -sf $(pwd)/bin/node /usr/local/bin
$ sudo ln -sf $(pwd)/bin/npm /usr/local/bin

查看node和npm版本

$ node -v
v14.21.3
$ npm -v
6.14.18

二、安装nrm

nrm是npm源管理器,可以切换不同源。

$ npm install -g nrm

查看npm的bin目录

$ npm -g bin
/home/songzehao/tmp/node-v14.21.3-linux-x64/bin
(not in PATH env variable)

将npm的bin下的nrm等命令,加到环境变量

$ sudo vim /etc/profile
export NPM_HOME=/home/songzehao/tmp/node-v14.21.3-linux-x64/bin
export PATH=$PATH:$NPM_HOME
$ source /etc/profile

查看nrm的版本

$ nrm -V
1.2.5

查看npm源

$ nrm ls
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/

三、注册npm

注册npm账号:https://www.npmjs.com

配置开启2FA:https://docs.npmjs.com/configuring-two-factor-authentication

选择authenticator application方式,可以下载Google Authenticator,扫码输入app里的验证码。

登录npm账号(需要在Google Authenticator中接收验证码并最后输入)

$ npm login
Username: peace0127
Password: 
Email: (this IS public) peace0127@163.com
npm notice Please use the one-time password (OTP) from your authenticator application
Enter one-time password: 119498
Logged in as peace0127 on https://registry.npmjs.org/.

nrm使用npmjs的源

$ nrm use npm
   Registry has been set to: https://registry.npmjs.org/

四、发布

新建一个nodejs工程

$ mkdir test && cd test

配置package.json,项目名称要避免重复,也避免不正式,否则可能被检测为垃圾

$ vim package.json
{
    "name": "eth-nodejs-sdk",
    "version": "1.0.0"
}

发布

$ npm publish --access=public
npm notice 
npm notice 📦  eth-nodejs-sdk@1.0.0
npm notice === Tarball Contents === 
npm notice 57B package.json
npm notice === Tarball Details === 
npm notice name:          eth-nodejs-sdk                          
npm notice version:       1.0.0                                   
npm notice package size:  154 B                                   
npm notice unpacked size: 57 B                                    
npm notice shasum:        008f0bf8913361a35b418045e6f0d92527902e02
npm notice integrity:     sha512-2umjB59NbwiKB[...]QxL0Y7DiauSwg==
npm notice total files:   1                                       
npm notice 
This operation requires a one-time password.
Enter OTP: 256965
+ eth-nodejs-sdk@1.0.0

安装验证

$ npm i eth-nodejs-sdk
npm WARN peace001@1.0.0 No description
npm WARN peace001@1.0.0 No repository field.
npm WARN peace001@1.0.0 No license field.

+ eth-nodejs-sdk@1.0.0
added 1 package and audited 121 packages in 1.77s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DayDayUp丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值