module.exports可以公开一个变量、数组、对象、方法等
require可以引入一个项目依赖一个自定义模块等
cmd命令E:\学习\node\vue\1.vue>
E:\学习\node\vue\1.vue>
E:\学习\node\vue\1.vue>cd ../
E:\学习\node\vue>cd ..\
E:\学习\node>md 2.node
E:\学习\node>cd 2.node
E:\学习\node\2.node>cd.>index.js
E:\学习\node\2.node>cd.>mod.js
E:\学习\node\2.node>dir
驱动器 E 中的卷没有标签。
卷的序列号是 F6E8-91F5
E:\学习\node\2.node 的目录
2021/01/24 16:03 <DIR> .
2021/01/24 16:03 <DIR> ..
2021/01/24 16:03 0 index.js
2021/01/24 16:03 0 mod.js
2 个文件 0 字节
2 个目录 562,830,184,448 可用字节
E:\学习\node\2.node>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See
npm help initfor definitive documentation on these fields
and exactly what they do.
Use
npm install afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (2.node) index
version: (1.0.0)
description: module.exports和reuqire的使用
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to E:\学习\node\2.node\package.json:
{
"name": "index",
"version": "1.0.0",
"description": "module.exports和reuqire的使用",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes) y
初始化好了项目
module.exports可以使用赋值对象在对象里可以赋值变量,方法,数组等,但不能直接赋值变量如下
rueqire后面用到会很多引入http等一些方法等