当前位置:网站首页>require modular syntax
require modular syntax
2022-08-02 03:38:00 【cjx177187】
node.js环境中的全局函数:require
front-endjs文件用import
The backend runtime introduces a third partyjs文件 就用require()也可以用import(es6语法)
node.js中有3种模块
====>内置模块===>核心模块【node.jsIt is configured during installation】
var fs=require("fs")
====>第三方模块 【下载后使用】npm I 模块名
var mime=require("mime")
====>自己定义的模块
var mytool=require("mytool")
举例:
利用requireImport an own modulemytool,然后调用mytool模块中的tool函数
注意:Fill in the correct path,The suffix name is best written
代码:
var mytool=require("./mytool.js")
mytool.tool()
新建一个mytool.js在里面导入 what we want to calltool函数
代码:
module.exports={
tool(){
console.log(6666)
}
}
运行代码

require是导出,exports是导入
注意要和ES6in the import syntax to distinguish yo!
ES6===>export default{}
node.js====>module.exports={}
The difference between the three modules:
The built-in modules can be used directly without downloading in advance.Both built-in modules and third-party modules need to be downloaded,Otherwise, the small black window will report an error during runtime,Says the module is not found.When the third-party magic module is imported, fill in the required importjs文件的路径.
require(“fs”)Where to look for files?
去当前项目中的node_modules文件中找fs文件夹中的package.json中mainThe path corresponding to the field is then imported;没有就去nodeIt is also found in the global installation package path in the installation packagepackage.json中mainThe path corresponding to the field is then imported;如果还是没找到,It will go to the core library to show off and find it,If you still can't find it, you will get an error
流程:
- 当前项目的node_modules文件夹
- in the global installation packagenode_global文件夹===>node_modules文件夹
- in the global installation packagenode_modules文件夹===>npm===>node_modules文件夹[核心库]
边栏推荐
- C语言 内联函数
- 广州华为面试总结
- subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
- nucleo stm32 h743 FREERTOS CUBE MX配置小记录
- Debian 10 NTP 服务配置
- [Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
- docker 安装 sqlserver中的坑点
- ModuleNotFoundError No module named 'xxx' possible solutions
- String comparison size in MySQL (date string comparison problem)
- 环形链表---------约瑟夫问题
猜你喜欢

ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决

排序学习笔记(二)堆排序

MySQL中字符串比较大小(日期字符串比较问题)

一个结构体 = 另一个结构体(同类型结构体之间可直接赋值操作)

利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置

Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide

Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000

语义分割标签即像素值的巨坑,transforms.ToTensor()的错误使用

npm--package.json---require

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
随机推荐
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
猴子选大王
[Learning Records of Boxue Valley] Super summary, share with heart | Software Testing Interface Testing Basics
display,visibility,opacity
磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG
微信小程序实现文本安全监测
Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
页面加载流程
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
知识工程作业2:知识工程相关领域介绍
ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决
Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000
Problems when yolov5 calls ip camera
【面试】失败的一次面试
@Autowired详解[email protected]在static属性上的使用
MySQL中字符串比较大小(日期字符串比较问题)
[Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
basic operator
科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
mysql创建表