npm 常用命令

未结帖
0 735
ajian admin_jim 2017-12-13
悬赏:5飞吻


$("code").each(function(a,b){var t=$(b).context.innerText;console.log(t)});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

https://jspang.com/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

https://nodejs.org/dist/


////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

相关命令

nvm list 查看已经安装的版本

nvm list installed 查看已经安装的版本

nvm list available 查看网络可以安装的版本

nvm version 查看当前的版本

nvm install 安装最新版本

nvm nvm use <version> ## 切换使用指定的版本

node nvm ls 列出所有版本 nvm current显示当前版本

nvm alias <name> <version> ## 给不同的版本号添加别名

nvm unalias <name> ## 删除已定义的别名

nvm reinstall-packages <version> ## 在当前版本node环境下,重新全局安装指定版本号的npm包

nvm on 打开nodejs控制

nvm off 关闭nodejs控制

nvm proxy 查看设置与代理

nvm node_mirror [url] 设置或者查看setting.txt中的node_mirror,如果不设置的默认是 Index of /dist/

nvm npm_mirror [url] 设置或者查看setting.txt中的 npm_mirror,如果不设置的话默认的是: https://github.com/npm/npm/archive/

nvm uninstall <version> 卸载制定的版本

nvm use [version] [arch] 切换制定的node版本和位数

nvm root [path] 设置和查看root路径


                        

原文链接:https://blog.csdn.net/weixin_57844432/article/details/127788884

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////


`npm set registry https://registry.npm.taobao.org/`。使用`npm config list`查看npm源地址是否已更改。



使用nrm管理npm源。nrm是一个专门管理npm源地址的工具,可以方便地切换npm源地址。首先,全局安装nrm。`npm install nrm -g --save`。然后,使用`nrm ls`查看当前源地址。可以使用`nrm use taobao`来切换到淘宝镜像,或者使用`nrm add r_name r_url`添加新的镜像地址。如果需要删除某个镜像地址,可以使用`nrm del r_name`。测试镜像速度可以使用`npm install -g nrm-check`。1345


使用阿里定制的cnpm命令行工具代替默认的npm。输入以下命令进行安装。`npm install -g cnpm --registry=https://registry.npm.taobao.org`。以后安装插件只需要使用`cnpm install`即可。如果习惯了npm,又不想使用cnpm,可以输入以下命令。`npm config set registry https://registry.npm.taobao.org`。然后输入`npm config list`查看是否已换源。



npm install [-g] 本地或全局安装模块


npm install node-sass@6.0.1 --save-dev


npm uninstall [-g] 本地或全局卸载模块


npm update 更新模块


npm ls 查看安装的模块


npm list 列出已安装模块


npm show  显示模块详情


npm info 查看模块的详细信息


npm search 搜索模块


npm publish 发布模块


npm unpublish 删除已发布的模块


npm -v 或 npm version显示版本信息


npm view npm versions 列出npm 的所有有效版本


npm install -g npm@2.14.14 /npm update -g npm@2.14.14  安装指定的npm版本


npm init 引导创建一个package.json文件,包括名称、版本、作者这些信息等


npm outdated  #检查模块是否已经过时


npm root  [-g] 查看包的安装路径,输出 node_modules的路径,


npm help 查看某条命令的详细帮助 例如输入npm help install


npm config 管理npm的配置路径


npm cache clean 清除 (如果有安装 cnpm,还需要清除 cnpm 的缓存:cnpm cache clean)




node.js 升级到指定版本

要将 Node.js 升级到特定的版本,可以按照以下步骤进行操作:


首先需要确认当前安装了哪些版本的 Node.js。在命令行中运行 nvm ls(如果使用 nvm)或者 npm list -g --depth=0 node(如果没有使用 nvm)来查看已经安装的 Node.js 版本列表。


选择想要升级到的目标版本号。比如我们希望升级到 v14.17.3 这个版本。


根据所使用的包管理工具不同,选择相应的命令进行升级。


a) 如果使用 npm,则可以通过以下命令全局安装最新版本的 Node.js:npm install -g n@latest。然后再次运行 nvm ls 或 npm list -g --depth=0 node 来确保已成功更新为目标版本。




https://ant-design.antgroup.com/docs/react/introduce-cn?ivk_sa=1026860b


https://www.jb51.net/article/214096.htm



环境

1.    nvm安装 https://github.com/coreybutler/nvm-windows/releases/tag/1.1.9

      nvm list available

  安装

  nvm install 16.17.1

  卸载

  nvm uninstall 16.17.1

安装项目   

2.    


      npm install -g create-react-app@3.4.1

      npm install -g antd@4.3.3

  npx create-react-app project-name

  

  cd project-name

  npm i react-dom@16.10.1 --legacy-peer-deps

  npm i react@16.10.1 --legacy-peer-deps

  npm install node-sass@6.0.1 --save-dev

  npm install sass-loader@10.2.0   --save-dev

  

笔记

3.

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     var 没有块级作用域 let有块级作用域  const 只能赋值一次 复制后不可再次复制更改 比如 const PI="圆周率",或者定义对象、函数防止更改

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


  解构赋值

[a, b]=[10, 20]       [a, , b]=[10, 20, 30] 10给a 30给b 20空出      [a, b, ...rest] = [10, 20, 30, 40, 50] 10给a 20给b    [30,40,50]当作数组给 rest

const [a, b] = [40, 50, 60] //直接解构赋值声明变量

[a=5, b=7] = [1];   此处a=1

对象解构赋值

let a, b;

({a, b}={ a: 10, b: 20 });

({a, b, ...rest}={ a: 10, b: 20, c: 30, d: 40 }); 

const {a, b, ...rest}={ a: 10, b: 20, c: 30, d: 40 }; 属性 a赋值给变量a ,属性b赋值给变量b,其余的保存到rest中

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


  展开运算

     function fn(a,b,c){

     console.log(a+b+c);

     return a+b+c;

}   

const arr = [1,2,3];

let result = fn(...arr);

此时result=6;  

let res = fn(arr)

此时 res = 1,2,3undefinedundefined

 

const arr2 = [...arr]; //潜赋值

const arr3 = [6,7,8, ...arr];

const arr4 = [6,7,8, ...arr, 9,10,11];

 

const = obj ={

     name:"孙悟空",

age:18,

gender:"男"

}

 

const obj2 = {...obj}  //潜赋值

const obj3 = {...obj, address:'花果山'}  

const obj4 = {address:'花果山', ...obj}  

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

  箭头函数   箭头后面的是返回值 一定是个有返回值的表达式

     

  

     原生函数 :

const fn = function(a){

     return a+"hello";

}

     只有一个参数:                 const fn = a => a+"hello";

没有参数、有多个参数 :         const fn=(a,b)=>a+"hello"+b;

     返回值是一个对象 需要加括号:   const fn=(a,b)=>({"aa":a,"bb":b});

 

返回值是代码块:

const fn=(a,b)=>{

     if(a==10){

    return a+b+10;

}

     if(a==20){

    return a+b+20;

}

});

 

 

!!!箭头函数中没有arguments

!!!箭头函数中没有自身的this,是他外层的this

!!!箭头函数中的this无法通过call、apply、bind修改

!!!箭头函数无法作为构造函数 无法 "new 一个"

 

const fn = () =>{

     console.log(this);   

}

fn();  //window对象

 

const obj={

     hello:()=>{

     console.log(this);  

}

}

obj.hello();  //window对象 

 

const obj2={

     hello:function(){

      console.log("111",this);

      const test = ()=>{

console.log("222",this);

}

test();

}

}

 

obj2.hello();   //obj对象 

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

    模块化  export  import  好处:可选择性导出和导入部分模块内容


    新建一个js 文件    m1.js  


            const a = 10;

            const b = 20;

            const objc = {name: '孙悟空' };

const fn = () => {

    console.log("我是个fn");

}

export defualt a;   // export defualt 一个模块中只能有一个默认导出 默认导出此处 a 可以随便写 并不是代码中的常量 a

const a = 10;

            exoprt const b = 20;    //命名导出

            exoprt const objc = {name: '孙悟空' };    //命名导出

const fn = () => {

    console.log("我是个fn");

}

export defualt a;   // export defualt 一个模块中只能有一个默认导出 默认导出此处 a 可以随便写 并不是代码中的常量 a

const a = 10;

            exoprt const b = 20;    //命名导出

            exoprt const objc = {name: '孙悟空' };    //命名导出

const fn = () => {

    console.log("我是个fn");

}

export defualt a;   // export defualt 一个模块中只能有一个默认导出 默认导出

export {b,fn};  //批量命名导出  

    新建一个引用文件 im.html    注意 script 标签默认不能使用 import  ,必须设置 type属性为module  导入的模块路径必须写完整,扩展名也得写  (./../...../dc.js)

import a from './m1.js';

<html>

    <body>

<script type="module">

    import a from './m1.js';   //导出默认模块部分   //a可以随便写 写haha也行  反正导出的是默认的部分

    import {b ,c} from './m1.js';//导出命名模块部分

console.log(a);

console.log(b);

console.log(c);

import {b as hello ,c} from './m1.js';  //改名导出

import a,{b as hello ,c} from './m1.js';/导出默认+命名部分

console.log(hello);

</script>

</body>

</html>

   

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


类 class 中定义的方法 fn()   this  不是固定的

    在类中方法的this不是固定的:以方法形式调用时,this是当前实例;以函数形式调用时 this是undefined

类中的所有代码都会默认在严格模式下执行  'use strict'

如果类中方法是以箭头函数定义的,则方法中的this恒为当前实例

class MyClass{

fn(){

     console.log(this);

}

}

const mc = new MyClass();

mc.fn();      //console.log() 出来的 this 是 MyClass {}

const test = mc.fn();

test(); // 以函数形式调用 console.log() 出来的 this 是 undefine

class MyClass{

fn =()=>{

     console.log(this);

}

}


{
"name": "traffic-react-admin",
"version": "0.1.0",
"private": true,
"dependencies": {
"@ant-design/icons": "^5.3.0",
"animate.css": "^3.7.2",
"antd": "^4.24.15",
"axios": "^0.19.0",
"braft-editor": "^2.3.8",
"echarts": "^4.4.0",
"nprogress": "^0.2.0",
"react": "16.10.1",
"react-dom": "16.10.1",
"react-loadable": "^5.5.0",
"react-redux": "^7.1.1",
"react-router-dom": "^5.1.1",
"react-scripts": "4.0.3",
"redux": "^4.0.4",
"screenfull": "^5.0.0"
},
"devDependencies": {
"@types/react": "17.0.20",
"@types/react-dom": "17.0.9",
"babel-plugin-import": "^1.12.2",
"customize-cra": "^0.8.0",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"node-sass": "^6.0.1",
"prettier": "^1.18.2",
"react-app-rewired": "^2.1.4",
"sass-loader": "^10.2.0",
"typescript": "4.4.2",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}


热忱回答0


最近热帖

近期热议

  1. javascript——prototype与__proto 9
  2. Mysql 中出现的Data truncated for column 3
  3. 在nginx中使用x-sendfile的解决方案 3
  4. 高版本jQuery面插件实现Ajax上传图片 1
  5. Thinkphp Socket.class.php 类的使用 1
  6. 使用ionic3创建第一个App 0
  7. ios-oc html5 0
  8. nginx.conf 0
  9. 基于ionic3.4.0的项目搭建 0
  10. php 缩略图 0