About node package version and npm commands
This writing explains node package version and some of npm commands.
1. Node package version
- Node packages always have three-digit versions. The reason for the three-digit version numbering is that it follows the SemVer (Semantic Versioning) version numbering scheme.
- If the version is 1.3.4,
- The first digit 1 is major version. If it is 0 it means it is under initial development. From 1 it means official version. A major version is released when the contents of a package have been modified to the point where they are no longer backward compatible.
- The second digit 3 is minor version. Minor versions are updated when it is backward compatible.
- The third digit 4 is patch version. A patch version is released when a problem with an existing feature has been fixed rather than when a new feature has been added.
- If the major version of a package you depend on has been updated, you should be careful as there is a high possibility that it will be incompatible with your existing code. On the other hand, most of minor or patch version updates can be upgraded without problem.
2. Symbol before version (^, ~)
- package.json has symbols like ^, ~, >, < before the version. These symbols are not included in the version, but they indicate which version to install or update.
- This symbol is used mostly and it means update or install until minor version.
$ npm i express@^1.1.1
- For example, it installs from 1.1.1 to 2.0.0. The version 2.0.0 will not be installed.
2-2. ~ symbol
- This symbol means update or install until patch version.
$ npm i express@~1.1.1
- For example, it installs from 1.1.1 to 1.2.0. The version 1.2.0 will not be installed.
2-3. @latest, @next
- @latest installs the latest stable version of a package. It can also be expressed as x.
$ npm i express@latest $ npm i express@x
- @next installs latest version but it can install alpha or beta version which is not stable yet.
$ npm i express@next
3. Other npm commands
3-1. npm outdated
$ npm outdated
$ npm outdated
- npm outdated command check if there is any old version package in dependencies of the root project. npm outdated --all can check all meta-dependencies.
$ npm outdated --all Package Current Wanted Latest Location Depended by array-flatten 1.1.1 1.1.1 3.0.0 node_modules/array-flatten express balanced-match 1.0.2 1.0.2 3.0.1 node_modules/balanced-match brace-expansion binary-extensions 2.3.0 2.3.0 3.0.0 node_modules/binary-extensions is-binary-path ...
- If "Current" and "Wanted" is different, it needs update. In such case you can update it with: npm update [package name]
3-2. npm uninstall
$ npm uninstall [package name]
$ npm uninstall [package name]
- It removes the package. Package will be removed from node_module folder and also from package.json. It can be shorten as: npm rm [package name]
3-3. npm search
$ npm search [some words]
$ npm search [some words]
- It can search for some packages. The keywords property in package.json is used in this case. In the Windows or Mac, it will be easier in browser. (https://npmjs.com)
3-4. npm info
$ npm info [package name]
$ npm info [package name]
- It shows detail information of the package such as dependencies, available version etc.
$ npm info express express@4.21.2 | MIT | deps: 31 | versions: 282 Fast, unopinionated, minimalist web framework http://expressjs.com/ keywords: express, framework, sinatra, web, http, rest, restful, router, app, api ... dependencies: accepts: ~1.3.8 cookie: 0.7.1 encodeurl: ~2.0.0 finalhandler: 1.3.1 ... published 3 months ago by jonchurch <npm@jonchurch.com>
- Other commands you can see more in CLI (Command Line Interface) of npm official documents: https://docs.npmjs.com/
Next step
- The next one is about how to publish your package.
Comments
Post a Comment