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

Redis simple study notes

Living to detect the Adaptive Normalized Representation Learning for GeneralizableFace Anti - Spoofing reading notes

微信小程序全局组件的定义

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

利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置

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

如何查看一个现有的keil工程之前由什么版本的keil IDE编译

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

parser = argparse.ArgumentParser()解析

微信小程序云开发如何将页面生成为pdf?
随机推荐
URL模块
基本运算符
sh: 1: curl: not found
canvas--pie chart
L1-043 阅览室 (20分)
Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000
[Learning Records of Boxue Valley] Super summary, share with heart | Software Testing Interface Testing Basics
猴子选大王
AttributeError: Can't get attribute 'SPPF' on
Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000
STM32 触发HardFault_Handler如何查找原因
钟表刻度线
暴力方法求解(leetcode14)查找字符串数组中的最大公共前缀
cross-domain problem solving
ssm various configuration templates
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
枚举法方法:(leetcode1300)转变数组后最接近目标值的数组和
JJWT tool class
sh: 1: curl: not found
微信小程序云开发如何将页面生成为pdf?