当前位置:网站首页>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文件夹[核心库]
边栏推荐
猜你喜欢

FreeRTOS内核详解(1) —— 临界段保护原理

STM32 CAN过滤器

【我的创作纪念日】 3周年

啃瓜记录第一天

DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent

parser = argparse.ArgumentParser() parsing

mysql卸载详细教程

@Autowired与@Resource区别

URL模块

Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000
随机推荐
【装机】老毛桃的安装及使用
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
动态代理工具类
subprocess.CalledProcessError: Command 'pip install 'thop'' returned non-zero exit status 1.
STM32 map文件解析
--fs模块--
yolov5调用ip摄像头时出现的问题
DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
Dynamic proxy tool class
__dirname
Error in render: “TypeError: Cannot read properties of null (reading ‘0‘)“ 报错解决方案
Chapter 10 Clustering
3分钟带你了解微信小程序开发
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
MySql创建数据表
ssm various configuration templates
FreeRTOS内核详解(1) —— 临界段保护原理
Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
C语言入门小游戏—三子棋
钟表刻度线