首页 > 其他分享 >[ NPM 01 ] js包管理工具 基础

[ NPM 01 ] js包管理工具 基础

时间:2022-11-22 16:35:26浏览次数:56  
标签:NPM npm 01 package -- js will version download

Node Package Manager


npm -v : show the version , or npm --version

In the nodejs or javaScript world , package.json is the most important file, it manifest file with app info, list dependencies, specify version and so on.

1 Basic Usage

1.1 Init

  • just npm init, gonna create package.json file, and need to choose package name, entry point(lots of time it's index.js), and other things.

  • if it's ok to skip all questions, just npm init --yes will keep default answers.

    • the npm system default value will be storaged in file .npmrc, path: /Users/macUser/.npmrc, if put some value in it first: npm config set init-author-name "my name", then when use npm init -y, the author will read this config file automaticlly.(also can set init-license and so on).

1.2 download dependencies

  • npm install lodash --save , if without --save, it will just download this package to folder node_modules, but do not add this dependency into the file package.json

  • run npm install when download a new project.

  • npm install gulp gulp-sass --save-dev will create dev dependencies, only used for dev.

  • for dependencies and devdependencies, if we clone a new project, npm install will download all dependencies(regular and dev ), but    npm install --production will only download dependencies( only regular).

1.3 uninstall dependencies

  • npm uninstall gulp --save-dev, remember to add --save-dev or --save behide the command, which make sure that package.json file will be updated.

1.4 download special version dependency

  • npm install [email protected] --save

  • update dependency to the latest version: npm update lodash

1.5 Download global dependency(on the machine)

  • npm install nodemon -g , which will not download into the project folder, will not add to the package.json file; use npm root -g can see where this nodemon dependency existed. (nodemon is a package wich will monitor every change in project and compile and run project after any changing, another one is live-server)

2. Semantic versioning

but for dependency, if : "lodash": "^4.17.4",

  • caret symbol ^: means if this dependency's minor version or patch version been updated, it will pull the latest minor version or patch version mirror.

  • tilde symbol ~: means if this dependency's patch version has been updated, it will pull the latest patch version mirror only!

  • without any symbol, will just download the special version

  • if it's "lodash": "*", will download the latest version mirror, whatever a new major version or others.

3. Other operation

  • npm list list all dependencies

  • npm list --depth 0 only one level

if add some scripts into the package.json,

except start and test can use npm start ornpm test, others all need use npm run xxx

标签:NPM,npm,01,package,--,js,will,version,download
From: https://www.cnblogs.com/Roy2048/p/16915525.html

相关文章

  • TXW8301入围 “中国芯” 芯火新锐产品评选
    11月17日​集成电路领域首个部省主办的国际化大会​具有风向标意义的专业化大会​2022世界集成电路大会在合肥拉开帷幕​近200多位领军人物、顶级专家,300余家行业企业齐聚合......
  • nodejs02
    Express快速创建Web服务器express的基本使用先安装express包[email protected].导入expressconstexpress=require('express');2.创建web服务器cons......
  • Newtonsoft的高级玩法,让你的json字符串与众不同
    json一经出现就得到多很多开发员的青睐,数据传输直接取代了之前的xml格式,不过也确实非常好用。关于json的常用操作,可以参考这篇文章。今天要分享的是Newtonsoft这个类库对Js......
  • js10行代码实现屏幕录制
    varbody=document.body;body.addEventListener("click",asyncfunction(){varstream=awaitnavigator.mediaDevices.getDisplayMedia({video:true});......
  • [SCOI2016]萌萌哒
    题目描述题面一个长度为\(n\)的大数,用\(S_1S_2S_3\cdotsS_n\)表示,其中\(S_i\)表示数的第\(i\)位,\(S_1\)是数的最高位。告诉你一些限制条件,每个条件表示为四......
  • C# 使用AD域控(Windows身份验证),跨域请求报错401
    书接上文,上篇指路......
  • 如何修改服务器的用户名和密码Windows2008/2012
    在我们刚拿到服务器的时候密码都是系统随机生成的初始密码,所以这时候我们一般第一时间拿到服务器应该为了安全起见先修改服务器密码以免密码泄露避免发生一些没必要的事情。......
  • EluxJS-让你像切蛋糕一样拆解前端巨石应用
    大家好,EluxJS是一套基于“微模块”和“模型驱动”的跨平台、跨框架『同构方案』,欢迎了解...可怕的巨石怪工作中最可怕的是什么?是遇到业务复杂且乱作一团的巨石应用。改一......
  • C:\Users\Administrator\AppData\Roaming\npm\yarn.ps1
    C:\Users\Administrator\AppData\Roaming\npm\yarn.ps1系统上禁止运行脚本。导致此错误的原因是,PowerShell执行策略,默认设置为Restricted不加载配置文件或运行脚本。......
  • 前端014-后台布局3--absolute+overflow
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>css后台布局</title><style>body{margin:0}/*去掉边框,*/.page-heade......