当前位置:网站首页>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文件夹[核心库]
边栏推荐
- Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
- Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- Chapter 10 Clustering
- C语言 十六进制整数字符串转十进制整数
- C语言 结构体定义方法
- 【我的创作纪念日】 3周年
- Usage of JOIN in MySQL
- L1-020 帅到没朋友 (20分)
- 小程序 van-cell 换行能左对齐问题
- 跨域问题解决
猜你喜欢

C语言的变长数组

STM32 触发HardFault_Handler如何查找原因

Usage of JOIN in MySQL

解决MySQL创建子视图并查看的时候,字符集报错问题

js basics

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

PCL—point cloud data segmentation

【 application 】 life many years of operations, what turned scored 12 k + annual bonus salary?

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

我的小笔记 =》原生微信小程序
随机推荐
js基础知识
语义分割标签即像素值的巨坑,transforms.ToTensor()的错误使用
np.unique()函数
__dirname
ModuleNotFoundError No module named 'xxx' possible solutions
STM32 触发HardFault_Handler如何查找原因
js 数组去重的常用方法
L1-039 古风排版(C)
npm and package.json
Cloud server installation and deployment of Nacos 2.0.4 version
C语言 void和void *(无类型指针)
Customer Rating Control
微信小程序九宫格抽奖和转盘抽奖的实现
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
Living to detect the Adaptive Normalized Representation Learning for GeneralizableFace Anti - Spoofing reading notes
require模块化语法
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
猴子选大王(约瑟环问题)
Advanced gradient of skeleton effect, suitable for waiting for pictures