NPM you really do? (One)

What is NPM

npm what stuff? npm fact, Node.js package management tool (package manager). Why we need a package management tool? Because we develop on Node.js, we will use a lot of JavaScript code written by someone else. If we want to use a package written by someone else, always searching by name at the official website, download the code, extract, script introduced very cumbersome. So a centralized management tool emerged: put npm official website after everyone had put their own developed modules package, if you want to use, directly through npm installation can be directly used, there is no managed code which should be where to download. More importantly, if we want to use modules A, and module A turn depends on module B, module B in turn depends on module X and module Y, npm according dependencies, all dependent packages are downloaded and manage. Otherwise, manually manage on our own, certainly cumbersome and error-prone.

npm history

In the era of npm no, you're going to get a module, or a framework of what you way?

  • Get -> JQ
  • Get -> Boottrap
  • Get -> Underscore

Our GitHub

Of course, it was also a jQuery can go era of the world

We certainly can not accept this old programmer and inefficient thing, we need to be more efficient and more reasonable code management.
Think of other languages

Language Package management tools
Java maven
Python distribute、setuptools、distutils、easy_install、pip
PHP Composer

There's no front-end! Intolerable! At this time there are individuals stood out
Isaac Z. Schlueter GitHub below referred to (Issac)

General realization of ideas

  • Looking for a cloud service to manage all of the code
  • Then sit notice of jQuery, Bootstrap, etc. These frameworks use npm publish to submit code to the cloud service,
  • Others in the community if you want to use the code, you can download the code through npm install.
  • Download the complete code node_modules appear in the directory, it can be used by require introduction.

Follow-up development

Isaaz notice of jQuery John Resig, he would agree? This is not necessarily still unknown, but still have to do it. Only front-end development engineer Everyone knows that there is this thing will not recognize it. That npm is how quickly hot up in the front-end community do? npm development is with Node.js development of complementary. Node.js is a US programmer Ryan Dahl of work in Germany github address written. He wrote Node.js, but Node.js was missing a package manager, and he hit it off ,, and Isaaz final Node.js built npm. Then what we all know, Node.js fire.

package.json

When we are in an empty file npm init initialization of this document I was born,

I am here to find package.json express the

{
  "name": "express", // 包名
  "description": "Fast, unopinionated, minimalist web framework", // 包的描述
  "version": "4.13.3", // 包的版本号
  "author": { // 包的作者姓名
    "name": "TJ Holowaychuk",
    "email": "[email protected]"
  },
  "contributors": [ // 包的其他贡献者姓名
    {
      "name": "Aaron Heckmann",
      "email": "[email protected]"
    }
    // ...
  ],
  "license": "MIT", // 你应该为你的模块制定一个协议,让用户知道他们有何权限来使用你的模块,以及使用该模块有哪些限制。
  "repository": { // 包代码存放的地方的类型,可以是 git 或 svn,git 可在 Github 上。
    "type": "git",
    "url": "git+https://github.com/strongloop/express.git"
  },
  "homepage": "http://expressjs.com/", // 包的官网 url
  "keywords": [ // 关键字
    "express",
    "framework",
    "sinatra",
    "web",
    "rest",
    "restful",
    "router",
    "app",
    "api"
  ],
  "dependencies": { // 依赖包列表。如果依赖包没有安装,npm 会自动将依赖包安装在 node_module 目录下
    "accepts": "~1.2.12",
    // ...
  },
  "devDependencies": { // 开发环境的依赖包
    "after": "0.8.1",
    // ...
  },
  "engines": { // node版本范围
    "node": ">= 0.10.0"
  },
  "files": [
    "LICENSE",
    "History.md",
    "Readme.md",
    "index.js",
    "lib/"
  ],
  "scripts": { // 项目的生命周期个各个环节需要执行的命令。key是生命周期中的事件,value是要执行的命令。
    "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/",
    "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",
    "test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/"
  },
  "gitHead": "ef7ad681b245fba023843ce94f6bcb8e275bbb8e",
  "bugs": {
    "url": "https://github.com/strongloop/express/issues"
  },
  "_id": "[email protected]",
  "_shasum": "ddb2f1fb4502bf33598d2b032b037960ca6c80a3",
  "_from": "express@*",
  "_npmVersion": "1.4.28",
  "_npmUser": {
    "name": "dougwilson",
    "email": "[email protected]"
  },
  "maintainers": [
    {
      "name": "tjholowaychuk",
      "email": "[email protected]"
    }
    // ...
  ],
  "dist": {
    "shasum": "ddb2f1fb4502bf33598d2b032b037960ca6c80a3",
    "tarball": "http://registry.npmjs.org/express/-/express-4.13.3.tgz"
  },
  "directories": {},
  "_resolved": "https://registry.npmjs.org/express/-/express-4.13.3.tgz",
  "readme": "ERROR: No README data found!"
}
复制代码

So next time if you have this package.json you can directly download and install these dependencies. Package file will appear in node_modules inside.

Frequently used commands

Global and local installation to install
a lot of friends not initially know npm install -g -g and without distinction, npm package installed into a local installation (local), global installation (global) two kinds

npm install express          # 本地安装
npm install express -g       # 全局安装
复制代码

Local installation
1, the installation package is placed under ./node_modules (directory where npm run command), if not node_modules directory will be generated in the directory of the current directory node_modules execution command npm
2, may be introduced by local require () installed packages.
Global installation
1, the installation package will be placed in the / usr / local or your installation directory node
2, can be used directly from the command line

Uninstall module
now can be installed so there will be a way to uninstall module,

npm uninstall express
复制代码

Uninstalled later check whether the module exists

npm ls
复制代码

Update Module

npm update express

复制代码

We will NPM more knowledge you really do? (II) to explain all stay tuned.

Reproduced in: https: //juejin.im/post/5d031b2ae51d454d544abf43

Guess you like

Origin blog.csdn.net/weixin_34352005/article/details/93161765