Nodejs项目包发布

目录

  • 一、安装node和npm
  • 二、安装nrm
  • 三、注册npm
  • 四、发布

一、安装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) [email protected]
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   [email protected]
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
+ [email protected]

安装验证

$ npm i eth-nodejs-sdk
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

+ [email protected]
added 1 package and audited 121 packages in 1.77s

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

found 0 vulnerabilities

你可能感兴趣的:(Nodejs,npm,node.js,nrm)