当前位置:网站首页>NodeJs, all kinds of path
NodeJs, all kinds of path
2022-08-02 00:31:00 【H5_ljy】
Article table of contents
One, local relative path and absolute path
Local relative path:
Simply speaking, this file page is opened locally, and then relative to the path of this file, such as "./" means it is at the same level as this fileYou can also omit "./" and enter the file name directly, and "../" means it is the same level as the parent of this file.
On the ajax1.html page we want to get bilibili-img.png image, the relative path can be filled in "../img/bilibili-img.png"
Local absolute path:
The absolute path is the location of the file on the disk, starting with the disk name; the path where we right-click the file to copy the path is the local absolute path, for example, we want toGet the bilibili-img.png image, right-click and copy the path: G:\H5\dom\app\img\bilibili-img.png This is the absolute path.
Second, relative network path and absolute network path
Relative network path:
The directory path created based on the location of the web page that references the file.Therefore, when web pages saved in different directories refer to the same file, the paths used will be different, so it is called relative.This path is used in the same way as a local relative path, except that the file is opened on the server.
For example:
The user enters the URL:
"http://www.baidu.com/user/login"
A page is opened, and the src of an img in this page is: "./src/baidu.jpg”
What is the req.url that the server www.baidu.com will receive?
Answer: “/user/src/baidu.jpg”
Its real URL:"http://www.baidu.com/user/src/baidu.jpg"
Absolute network path:
The directory path referenced to the root of the web site.The reason why it is called absolute means that when all web pages refer to the same file, the path used is the same.Format: Protocol://ip:port/The location of the file under this server file;
The above picture is an example: when we use the app file as the root directory of the Web site, we need to get the bilibili-img.png picture,The path is:
http or https://local ip: server listening port number or domain name /img/bilibili-img.png
When we want to use pictures on the network, do not download and use them, copy the pathIt is an absolute path:
https://i0.hdslb.com/bfs/archive/7a2a097d57ce0d7c2c46585ff98c45368e7386eb.png
Third, local relative root path and network relative root path
Local relative root path:
When we only enter "/", it is relative to the path in the root directory of the disk where the file is located, for example
There is a path under my G driveImage
The path of the html file I run is G:\H5\dom\app\src\ajax1.html
We only need to fill in "\bilibili.png" when we visit this image
Click me
Click to access
Network relative root path
The fundamental relative root path is similar, the difference is relative to the root directory of the server running this file
For example:
User input URL:http://www.baidu.com/user/newspage
opened a page, in this page there is an img's src: "/src/baidu.jpg"
May I ask www.baidu.com thisWhat is the req.url that the server will receive?
Answer: "/src/baidu.jpg"
Its real URL is: "http://www.baidu.com/src/baidu.jpg"
Fourth, the global variable that displays the path in node.js
The global variable __dirname is a string representing the path of the directory where the current js file is located (absolute path)
The global variable __filename is a string representing the path (absolute path) of the current js file
边栏推荐
- Detailed explanation of JSP request object function
- Cyber-Physical System State Estimation and Sensor Attack Detection
- An interesting project--Folder comparison tool (1)
- What is the function of the JSP out.println() method?
- [Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
- Simpson's paradox
- 构造方法,this关键字,方法的重载,局部变量与成员变量
- 玩转NFT夏季:这份工具宝典值得收藏
- Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
- 重装腾讯云云监控后如果对应服务不存在可通过sc.exe命令添加服务
猜你喜欢
不要用jOOQ串联字符串
面试高频考题解法——栈的压入弹出序列、有效的括号、逆波兰表达式求值
bgp 聚合 反射器 联邦实验
【HCIP】BGP小型实验(联邦,优化)
SphereEx Miao Liyao: Database Mesh R&D Practice under Cloud Native Architecture
Short video SEO search operation customer acquisition system function introduction
nodeJs--各种路径
Arduino Basic Syntax
How to solve the error when mysql8 installs make
一文概览最实用的 DeFi 工具
随机推荐
Short video SEO optimization tutorial Self-media SEO optimization skills and methods
Transient Stability Distributed Control of Power System with External Energy Storage
Unknown CMake command “add_action_files“
JSP page指令errorPage属性起什么作用呢?
ROS dynamic parameters
Multi-feature fusion face detection based on attention mechanism
07-SDRAM :FIFO控制模块
认识USB、Type-C、闪电、雷电接口
460. LFU 缓存
Ansible中的任务执行控制
JSP out.write()方法具有什么功能呢?
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
A simple file transfer tools
Cyber-Physical System State Estimation and Sensor Attack Detection
中缀转后缀、前缀表达式快速解决办法
CRS 管理与维护
【HCIP】BGP小型实验(联邦,优化)
146. LRU cache
nodeJs--各种路径
这 4 款电脑记事本软件,得试试