npm 发布和下载包

npm 发布和下载包

1. 使用npm注册的账号进行登录

npm login

2. 登录成功后,查看当前用户

npm whoami

image-20220616172641848

3. 初始化项目的文件夹

npm init

image-20220616172745277

image-20220616172812926

初始化完成后,文件夹中会多出一个package.json 文件

4. 推送要发布的包到 npm 上

npm publish

发现出现错误,原因:使用的项目名称在npm上已经存在,需要重新改个名字

Administrator@10_0_4_14 MINGW64 ~/Desktop/npm测试文件夹
$ npm publish
npm notice
npm notice 📦  test@1.0.0
npm notice === Tarball Contents ===
npm notice 191B package.json
npm notice === Tarball Details ===
npm notice name:          test
npm notice version:       1.0.0
npm notice filename:      test-1.0.0.tgz
npm notice package size:  237 B
npm notice unpacked size: 191 B
npm notice shasum:        5c58f222b95e8ed3447ad9f8312a51cb7f7c5cbf
npm notice integrity:     sha512-vBCJNxAz61a8U[...]BvNlWvWwPnwAw==
npm notice total files:   1
npm notice
npm notice Publishing to https://registry.npmjs.org/
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/test - This package requires that publishers enable TFA and provide an OTP to publish. For more info, visit: https://go.npm.me/2fa-guide
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-06-16T09_21_04_884Z-debug-0.log

image-20220616173237654

再次推送成功

image-20220616173257222

image-20220616173324174

5. 下载npm上的包

npm install 包名 或者npm i 包名
npm i cm-song-test@1.0.0

image-20220616173721260

posted @ 2022-06-16 17:48  STR少寒  阅读(168)  评论(0编辑  收藏  举报