Publish a npm package of your own in one minute

Keywords: npm JSON git

How to publish an npm package

1. Register npm account

Landing https://www.npmjs.com Use email to register, receive and verify email
(here are two emails: Welcome to npm and Verify your npm email address)

2. Select the target folder and cd in the command line

E:\xxx>cd test
E:\xxx\test>

3. Execute npm init

Enter the following command, and you will be prompted to configure package related information, name version, etc., which are basic configuration information of the package

 E:\xxx\test> npm init
 
 Detailed configuration:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (npm-publish)                       //Package name
version: (1.0.0)                          //Version number
description:                              //describe
entry point: (index.js)                   // Entrance file
test command:
git repository:                          //git warehouse address
keywords:                                //Keyword
author:                                  //author
license: (ISC)                           //Open source protocol
About to write to E:\learn\node\npm-publish\package.json:

{
  "name": "fashaoge",
  "version": "0.0.1",
  "description": "the npm pulish test ��, only a test ,please don't install",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "test"
  ],
  "author": "hu-qi",
  "license": "ISC"
}


Is this ok? (yes)

4. After configuration, the package.json file will be generated and the package code will be written

Last sentence: Is this ok? (yes)
Create the index.js file / / write module.exports = 123456789;

5. Publish package: npm publish package name

Landing npm

 E:\xxx\test>npm login 
 E:\xxx\test>Username: yourname
 E:\xxx\test>Password: yourpassword
 E:\xxx\test>Email: (this IS public) youremail 
E:\xxx\test>npm publish 

Digression

1, A small mistake is that the result of the contract is wrong if it fails to pass the verification

npm ERR! publish Failed PUT 403
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\                                                                                            node_modules\\npm\\bin\\npm-cli.js" "publish"
npm ERR! node v6.3.0
npm ERR! npm  v3.10.3
npm ERR! code E403

npm ERR! you must verify your email before publishing a new package: https://www                                                                                            .npmjs.com/email-edit : 

2, Package deletion

npm --force unpublish package name

Original link: https://segmentfault.com/a/119000010399761

Posted by GamingWarrior on Tue, 31 Mar 2020 04:08:50 -0700