一、安装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"
}
发布文章来源:https://www.toymoban.com/news/detail-468895.html
$ 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
安装验证文章来源地址https://www.toymoban.com/news/detail-468895.html
$ 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
到了这里,关于Nodejs项目包发布的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!