运行在服务端的JS Node里面的模块系统遵循的是CommonJS规范
1.commonJS规范
CommonJS定义的模块分为:
- 模块标识(module)
- 模块定义(exports)
- 模块引用(require)
2.exports与module.exports是一样的东西
3.npm
npm是node.js内置的一个包管理工具
- npm init 初始化项目 package.json main平时开发中基本用不到,只有我们在引用或者开发某个依赖包的时候才派上用场(给别人引用这个包)。不使用main属性的话我们可能需要这样写引用:require("some-module/dist/app.js"),如果我们在main属性中指定了dist/app.js的话,我们就可以直接引用依赖就可以了:require("some-module") ;test command 是项目启动时脚本命令
- npm install,npm就会根据package.json去寻找需要的函数库,也就是依赖
- $ npm install express
-
npm unpublish <package>@<version>
可以撤销发布自己发布过的某个版本代码 npm update <package>
可以把当前目录下node_modules
子目录里边的对应模块更新至最新版本-
删除以前安装的 node_modules 重新安装npm cache clean----> npm install
https://www.runoob.com/nodejs/nodejs-npm.html
设置镜像源 yarn(更告诉 更准确)
1、查看一下当前源yarn config get registry
2、切换为淘宝源yarn config set registry https://registry.npm.taobao.org
3、或者切换为自带的yarn config set registry https://registry.yarnpkg.com
yarn info <packageName>
可以用来查看某个模块的最新版本信息