当前位置:网站首页>npm --package.json---require
npm --package.json---require
2022-08-02 03:39:00 【cjx177187】
npm:
Instructions for the small black window:
i和install是一样的
npm i 模块名字x1 模块名字x2 模块名字x3 -g //把模块x1 x2 x3The three modules are downloaded to the global installation path
npm i 模块名字x1 模块名字x2 模块名字x3
或者
npm i 模块名字x1 模块名字x2 模块名字x3 --save //把模块x1 x2 x3The three modules are downloaded to the project installation path(inside the current project 的node_modules)
After downloading third-party modules npmThe downloaded third-party module name and version are written in the dependencies in the project configuration file
wait to learn laterwebpack就懂了
npm i x1 --save
npm i x1 --save-dev
npm i x1 -S
npm i x1 -D
npm i
这个指令 会去项目的配置文件中找到依赖的包 全部下载
npm run dev
这个指令会去项目的配置文件中找到scripts字段运行里面的dev指令
package.josn:
Configuration files belonging to the project 用于记录整个项目的一些信息===>项目名、作者信息
项目名==>项目的名字
"scripts":{"dev":"node index.js"} 启动指令 主要用于小黑窗的npm启动 npm run dev
"dependencies" 项目依赖
require:
node.js环境中的全局函数:require
引入前端的js文件用import
后端运行时引入第三方js文件 就用require()也可以用import(es6语法)
node.js中有3种模块
====>内置模块===>核心模块【node.js安装时就配置好的】
var fs=require("fs")
====>第三方模块 【下载后使用】npm I 模块名
var mime=require("mime")
====>自己定义的模块
var mytool=require("mytool")
举例:
利用require导入一个自己的模块mytool,然后调用mytool模块中的tool函数
注意:填写正确路径,后缀名最好的写上
代码:
var mytool=require("./mytool.js")
mytool.tool()
新建一个mytool.js在里面导入 我们想要调用的tool函数
代码:
module.exports={
tool(){
console.log(6666)
}
}
运行代码

require是导出,exports是导入
require(“fs”)会去哪里找文件?
去当前项目中的node_modules文件中 找fs文件夹中的package.json中main字段对应的路径然后引入;没有就去node的安装包中的全局安装包路径中找也是找package.json中main字段对应的路径然后引入;如果还是没找到,就会去核心库里卖弄去找,还是没找到就会报错
流程:
- 当前项目的node_modules文件夹
- 全局安装包中的node_global文件夹===>node_modules文件夹
- 全局安装包中的node_modules文件夹===>npm===>node_modules文件夹[核心库]
边栏推荐
- Cut out web icons through PS 2021
- PCL—point cloud data segmentation
- Deveco studio Hongmeng app access network detailed process (js)
- The usage of json type field in mysql
- URL模块
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- 新工程加载YOLOV6的预训练权重问题
- Source Insight 使用教程(2)——常用功能
- Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- [Mianjing] Mihayou data development on one side and two sides
猜你喜欢

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

通过PS 2021 将网页图标抠下来

Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000

mysql阶段总结

UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the index ing argu

How to check whether a table is locked in mysql

啃瓜记录第一天

docker中配置mysql 5.7

啃瓜记录又一天

小程序 van-cell 换行能左对齐问题
随机推荐
暴力方法求解(leetcode14)查找字符串数组中的最大公共前缀
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the index ing argu
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
The usage of json type field in mysql
AttributeError: Can't get attribute 'SPPF' on
动态代理工具类
ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决
DOM操作---放大镜案例
Phospholipid-polyethylene glycol-hydrazide, DSPE-PEG-Hydrazide, DSPE-PEG-HZ, MW: 5000
---静态页面---
第一篇博客
STM32 map文件解析
DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
ssm各类配置模板
远程调试、无cuDnn、自定义模块无法导入问题记录
npm和package.json
Customer Rating Control
微信小程序云开发如何将页面生成为pdf?
C语言的变长数组