6 Most Useful NPM commands that you may do not know yet

6 Most Useful NPM commands that you may do not know yet

·

4 min read

1. npm view <package> (View information) npm view to view information about the package

axios@1.2.0 | MIT | deps: 3 | versions: 66 Promise based HTTP client for the browser and node.js axios-http.com

keywords: xhr, http, ajax, promise, node

dist .tarball: registry.npmjs.org/axios/-/axios-1.2.0.tgz .shasum: 1cb65bd75162c70e9f8d118a905126c4a201d383 .integrity: sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw== .unpackedSize: 1.6 MB

dependencies: follow-redirects: ^1.15.0 form-data: ^4.0.0 proxy-from-env: ^1.1.0

maintainers:

dist-tags: latest: 1.2.0 next: 1.2.0-alpha.1

published a week ago by jasonsaayman jasonsaayman@gmail.com

Get only the version information about the axios (installed package):

$ npm view axios version
> 0.19.2

2. npm -h (Helper Method)

Usage: npm

where is one of: access, adduser, audit, bin, bugs, c, cache, ci, cit, clean-install, clean-install-test, completion, config, create, ddp, dedupe, deprecate, dist-tag, docs, doctor, edit, explore, fund, get, help, help-search, hook, i, init, install, install-ci-test, install-test, it, link, list, ln, login, logout, ls, org, outdated, owner, pack, ping, prefix, profile, prune, publish, rb, rebuild, repo, restart, root, run, run-script, s, se, search, set, shrinkwrap, star, stars, start, stop, t, team, test, token, tst, un, uninstall, unpublish, unstar, up, update, v, version, view, whoami

Especially, npm -h is a command to get a quick help for the specific . For example,

npm install -h shows some syntax usages available for install command

npm install -h

npm install (with no args, in package dir) npm install [<@scope>/] npm install [<@scope>/]@ npm install [<@scope>/]@ npm install [<@scope>/]@ npm install @npm: npm install npm install npm install npm install npm install /

aliases: i, isntall, add common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]

3. npm ls — only=<environment> (Advanced npm list )

npm ls --only=dev --depth=0
npm ls --only=prod --depth=0

-- @compodoc/compodoc@1.1.19 +-- @nestjs/cli@8.2.8 +-- @nestjs/schematics@8.0.11 +-- @nestjs/testing@8.4.7 +-- @types/express@4.17.13 +-- @types/jest@27.5.2 +-- @types/multer@1.4.7 +-- @types/node@16.11.56 +-- @types/nodemailer@6.4.5 +-- @types/supertest@2.0.12 +-- @types/webpack-env@1.18.0 +-- @typescript-eslint/eslint-plugin@4.33.0 +-- @typescript-eslint/parser@4.33.0 +-- aws-sdk@2.1205.0 +-- eslint@7.32.0 +-- eslint-config-prettier@8.5.0 +-- eslint-plugin-prettier@3.4.1 +-- jest@27.5.1 +-- jsdoc@3.6.11 +-- madge@5.0.1 +-- mammoth@1.4.21 +-- prettier@2.7.1 +-- supertest@6.2.4 +-- ts-jest@27.1.5 +-- ts-loader@9.3.1 +-- ts-node@10.9.1 +-- tsconfig-paths@3.14.1 +-- typescript@4.8.2 `-- UNMET PEER DEPENDENCY webpack@2.7.0

npm list is a useful command to show the installed packages

But often times, it brings TOO many installed packages and makes it almost impossible to see the list of installed packages

> │ ├─┬ schema-utils@2.6.6
> │ │ ├── ajv@6.12.2 deduped
> │ │ └── ajv-keywords@3.4.1 deduped
> │ └── semver@6.3.0 deduped
> ├── typescript@3.9.3
> ├── vue@2.6.11
> ├── vue-router@3.2.0
> ├─┬ vue-template-compiler@2.6.11
> │ ├── de-indent@1.0.2
> │ └── he@1.2.0
> ├── vue-typed-mixins@0.2.0
> ├── vuex@3.4.0
> └── vuex-typex@3.1.5

Development environment

> npm ls --only=dev --depth=0 // --depth=0 is an optional

It only shows what you have installed in dev environment

├── eslint@6.8.0 ├── eslint-plugin-import@2.20.2 ├── eslint-plugin-vue@6.2.2 ├── node-sass@4.14.1 ├── sass-loader@8.0.2 └── vue-template-compiler@2.6.11

Production environment

npm ls --only=prod --depth=0 // --depth=0 is an optional

It only shows what you have installed in prod environment

├── @vue/cli-plugin-typescript@4.3.1 ├── @vue/eslint-config-typescript@5.0.2 ├── core-js@3.6.5 ├── typescript@3.9.3 ├── vue@2.6.11 ├── vue-router@3.2.0 ├── vue-typed-mixins@0.2.0 ├── vuex@3.4.0 └── vuex-typex@3.1.5

4. npm install <package> (install command) install is the most useful and frequently used npm command. npm install command installs the specified modules

A command to install mysql module:

> npm install mysql

5. npm remove <package> (remove command) npm remove deletes the installed modules (The opposite of install command)

npm remove mysql

Also, npm uninstall deletes the installed modules

> npm uninstall mysql

6. npm outdated (show version of installed pacakges) Can find available updated packages using npm outdated :

Need updates if Current & Wanted is different

Update only certain package:

npm update [package name]

Thank you! I hope it's useful

Did you find this article valuable?

Support ramu k by becoming a sponsor. Any amount is appreciated!