当前位置:网站首页>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语言 十六进制整数字符串转十进制整数
parser = argparse.ArgumentParser()解析
小程序 van-cell 换行能左对齐问题
parser = argparse.ArgumentParser() parsing
oracle inner join and outer join
啃瓜记录又一天
远程调试、无cuDnn、自定义模块无法导入问题记录
ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决
Week 7 Review
@Autowired与@Resource区别
随机推荐
STM32 触发HardFault_Handler如何查找原因
mysql阶段总结
【程序人生】做了多年的运维,靠什么转行拿下12K+年终奖的薪资?
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
猴子选大王(约瑟环问题)
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
Dynamic proxy tool class
C语言 内联函数
ModuleNotFoundError No module named ‘xxx‘可能的解决方案大全
知识工程作业2:知识工程相关领域介绍
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Redis简单学习笔记
排序学习笔记(二)堆排序
The @autowired distinguished from @ the Resource
网址URL
__dirname
oracle inner join and outer join
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
MySQL中字符串比较大小(日期字符串比较问题)
Deveco studio 鸿蒙app访问网络详细过程(js)