2.0.1 • Published 5 years ago

basic_05_publish v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

the example is based on the following tutorial

https://medium.freecodecamp.org/how-to-create-and-publish-your-npm-package-node-module-in-just-10-minutes-b8ca3a100050


publish

$ npm init -y

by default, the package name is the same as directory name

change package name to basic_05_publish

create index.js as below

module.exports = (message) => message.toUpperCase();

$ npm login $ npm publish

go to https://www.npmjs.com/settings/jyang49/packages to see my packages

view the package detail

notice that the version is 1.0.0 which was set when running "npm init"

$ npm view basic_05_publish (or, npm view basic_05_publish --json) ... dist-tags: latest: 1.0.0


install and use package

from another directory

$ npm i basic_05_publish

create following app.js (or copy app.js)

const uppercaser = require('basic_05_publish');

console.log(uppercaser('hello world!'));

run app.js

$ node app.js


update package

make code change to index.js

module.exports = (message) => 'v1: ' + message.toUpperCase();

update version in package.json

this is required, because cannot publish package with the same version again

"version": "1.1.0",

pubish

npm publish

now the latest tag is associated with the version 1.1.0

if run npm install, will install version 1.1.0


delete package

npm unpublish basic_05_publish@1.1.0


update package with tag

update version in package.json

notice that even 1.1.0 was unpublished, still cannot use this version, which is by design for security reason

"version": "1.1.1",

$ npm publish --tag bugfix1

show tags

$ npm show basic_05_publish ... dist-tags: bugfix1: 1.1.1 latest: 1.0.0


managing tag

show tags

$ npm dist-tag ls basic_05_publish bugfix1: 1.1.1 latest: 1.0.0

remove tag

$ npm dist-tag rm basic_05_publish bugfix1

show tags again, now the tag bugfix1 was gone

$ npm dist-tag ls basic_05_publish latest: 1.0.0

add tag

$ npm dist-tag add basic_05_publish@1.1.1 bugfix11

add another tag

$ npm dist-tag add basic_05_publish@1.1.1 feature11

show tags. Notice that two tags associated with the same version

$ npm dist-tag ls basic_05_publish bugfix11: 1.1.1 feature11: 1.1.1 latest: 1.0.0


install package by tag

When specify specific tag, will ignore settings in package.json and package-lock.json

$ npm i basic_05_publish@feature11

$ npm i basic_05_publish@latest

2.0.1

5 years ago

2.0.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago