当前位置:网站首页>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文件夹[核心库]
边栏推荐
- oracle内连接和外连接
- yolov5调用ip摄像头时出现的问题
- Deveco studio 鸿蒙app访问网络详细过程(js)
- mysql中exists的用法详解
- 【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
- 配置mmdet来训练Swin-Transformer之一配置环境
- AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
- SOCKS5
- [Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
- Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
猜你喜欢

Debian 10 NTP 服务配置

STM32 map文件解析

远程调试、无cuDnn、自定义模块无法导入问题记录

配置mmdet来训练Swin-Transformer之一配置环境

URL模块

磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000

最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机

String comparison size in MySQL (date string comparison problem)

Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000

DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
随机推荐
yolov5调用ip摄像头时出现的问题
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
UserWarning:火炬。meshgrid:在以后的版本中,它将被要求通过索引ing argu
Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000
Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
Dynamic proxy tool class
npm--package.json---require
MySql创建数据表
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
Basic usage of Monaco Editor
【面经】米哈游数据开发一面二面面经
SSM integration
活体检测 Adaptive Normalized Representation Learning for GeneralizableFace Anti-Spoofing 阅读笔记
oracle inner join and outer join
SOCKS5
The usage of json type field in mysql
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Detailed explanation of the usage of exists in mysql
MySQL中JOIN的用法
np.unique()函数