当前位置:网站首页>2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)
2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)
2022-07-29 03:01:00 【Like to drink pearl milk tea】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
Catalog
(1)querystring.parse(str, [sep], [eq], [options])
(2)querystring.stringify(obj, [sep], [eq])
(1)mime.getExtension() You can return the resource type through the path
(2) mime.getType() You can return the resource type through the path
5. All kinds of paths ( Relative paths )
(6) Network relative root path
6. Loading of web pages ( Interview questions *)
1. route (_dirname,_filname)
_dirname,_filnam It's all global variables
(1) __dirname
Is a string , representative At present js file Directory of route ( Absolute path )
__dirname: Return the current module file After the analysis Folder in which ( Catalog ) The absolute path of
Use __dirname Variable to get the full directory name of the directory where the current file is located__dirname Equate to path.dirname(__filename)
(2)__filename
Is a string , representative At present js Path to file ( Absolute path )
__filename: Return the current module file The absolute path after parsing ,
Use __filename Variable to get the file name with the full absolute path of the current module file
2.url website
Composition of the website : agreement ://ip:port/pathname?querystring#hash
domain name ==>DNS analysis Will resolve the domain name into a ip port
Procedures such as :
var url=require("url") var str="http://www.baidu.com/20220728/news/page1/index.html?count=20&maxid=123456" var obj=url.parse(str) console.log(obj);Running results :
3.querystring modular
(1) querystring It literally means Inquire about character string , Usually yes. http Request the data to be parsed .querystring The module only provides 4 A way .
(2)querystring Parameter resolves to an object
(3)querystring Modules are used to implement URL Conversion between parameter string and parameter object
(1)querystring.parse(str, [sep], [eq], [options])
parse This method is to put a string Deserialization For an object .
querystring.parse(str, [sep], [eq], [options])------ Will a query string Deserialize to an object . You can choose whether to overwrite the default delimiter ('&') And allocators ('=').
Case study :
var querystring=require("querystring") var obj=querystring.parse("username=jack&count=20&maxid=123456") console.log(obj)Running results :
(2)querystring.stringify(obj, [sep], [eq])
------ Serialize an object to a query string.
You can choose whether to overwrite the default delimiter ('&') And allocators ('=').
give an example :
var querystring=require("querystring") var str2=querystring.stringify({name:"jack",age:20}) var str3=JSON.stringify({name:"jack",age:20}) console.log(str2); console.log(str3);Running results :
![]()
4.mime modular
mime It's an Internet standard , By setting it, you can set the opening mode of the file in the browser
(1)mime.getExtension() You can return the resource type through the path
give an example :
var mime=require("mime") var re=mime.getExtension("text/css") console.log(re)Running results :
(2) mime.getType() You can return the resource type through the path
give an example :
var mime=require("mime") var re2=mime.getType("htpp://2342354345:8080/css/sadfsdgfdfg.ttf") console.log(re2)Running results :
5. All kinds of paths ( Relative paths )
(1) Local relative path
for example : Write the path in the page : file://x1/x2/x2/index.html
"./src/18.jpg" The page of the file that writes this path is opened locally ==> file://x1/x2/x2/src/18.jpg
"src/18.jpg" The page of the file that writes this path is opened locally ==> file://x1/x2/x2/src/18.jpg
"file://c:/"
(2) Local absolute path
Write the path from the root drive letter
for example :"C:/Windows/ASUS/Shortcuts"
(3) Relative network path
for example :
The URL of the current page : " agreement ://ip:port /src/news/index.html querystring hash"
Path inside the page :
"./src/18.jpg" ==> " agreement ://ip:port /src/news/src/18.jpg"
"src/18.jpg" ==> " agreement ://ip:port /src/news/src/18.jpg"
reflection 1:
User input web address :"http://192.168.6.60:8080/user/20220728/newspage.html?n=20"
Opened a page , In this page, there is a img Of src yes : "./src/18.jpg"
Excuse me, 192.168.6.60:8080 This server will be affected req.url What is it? ?
answer : "/user/20220728/src/18.jpg"
reflection 2:
User input web address :"http://192.168.6.60:8080/user/20220728/newspage"
Opened a page , In this page, there is a img Of src yes : "./src/18.jpg"
Excuse me, 192.168.6.60:8080 This server will be affected req.url What is it? ?
answer : "/user/20220728/src/18.jpg"
Its real website :"http://192.168.6.60:8080/user/20220728/src/18.jpg"
(4) Absolute network path
" agreement ://ip:port /src/news/src/18.jpg"
Fallible thinking :
User input web address : http://192.168.6.60:8080/user/20220728/newspage
Opened a page , In this page, there is a img Of src yes : "192.168.6.60:8080/src/18.jpg"
Excuse me, 192.168.6.60:8080 This server will be affected req.url What is it? ?
answer : "/user/20220728/192.168.6.60:8080/src/18.jpg"
Its real website :"http://192.168.6.60:8080/user/20220728/192.168.6.60:8080/src/18.jpg"
(5) Local relative root path
reflection : The user opens locally : "file:///c:/xx/xx2/index.html"
There's a... In the page img Of src yes : "/src/18.jpg"
Its real path :"file:///c:/src/18.jpg"
(6) Network relative root path
reflection :
User input web address : http://192.168.6.60:8080/user/20220728/newspage
Opened a page , In this page, there is a img Of src yes : "/src/18.jpg"
Excuse me, 192.168.6.60:8080 This server will be affected req.url What is it? ?
answer :"/src/18.jpg"
Its real website :"http://192.168.6.60:8080/src/18.jpg"
6. Loading of web pages ( Interview questions *)
1. How do browsers load web pages ?
==>
(1.1) Browser address bar , Enter url , Knock back , Will request a server , The server will return a packet , Is the web code (html Document format ).
(1.2) The browser starts to run parsing html Text ( There is no external picture at this time ,js,css, Font library resources )
(1.2.1) When parsing , Yes img Labeled src attribute , It will be asynchronous , Start network request server again , The server returns packets ( Picture coding ) Then render it
(1.2.2) When parsing , Yes link-href It will be asynchronous , Start network request server again , The server returns packets (css code ), Then load .
(1.2.3) When parsing ,xxxx-url It will be asynchronous , Start network request server again , The server returns packets ( Corresponding code ) Then load .
(1.2.4) When parsing ,script-src It will be asynchronous , Start network request server again , The server returns packets (js code ), And then use js The engine executes the coding .
(1.3 ) All resources are loaded , Will trigger window.onload
边栏推荐
- HTB-Blue
- 明明开发薪资高,为什么我还是选了测试?
- C language: Little Lele and Euclid
- Why did I choose the test when the development salary was high?
- Weekly recommended short videos: how to make product development more effective?
- Verilog的时间系统任务----$time、$stime、$realtime
- Multithreading realizes concurrent reading and execution of multi use case files +selenium grid4 realizes distributed deployment of test framework
- HTB-Blocky
- Idea replaces the contents of all files
- Groupby method
猜你喜欢

DHCP protocol detailed analysis

算法---粉刷房子(Kotlin)

MySql的安装配置超详细教程与简单的建库建表方法

VASP calculation task error: M_ divide:can not subdivide 8 nodes by 6

Engineering boy: under 20 years old, ordinary but not mediocre

PHP process communication series (I) named pipes

Day 10 notes

HTB-Blocky

R language error: compilation failed for package '****‘

会议OA之反馈功能
随机推荐
算法---粉刷房子(Kotlin)
Idea replaces the contents of all files
【luogu P8352】小 N 的独立集(DP套DP)(性质)
What is SOA (Service Oriented Architecture)?
OWT server source code analysis (4) -- video module analysis of mixer out
Codeworks 5 questions per day (average 1500) - day 25
RestfulAPI——C#——增加header用户名密码验证
centos安装mysql8
万字详解 Google Play 上架应用标准包格式 AAB
PHP process communication series (I) named pipes
Notes on the ninth day
.net serialize enumeration as string
C language: judging letters
第09章_性能分析工具的使用
C语言程序设计 | 交换二进制数奇偶位(宏实现)
Advanced architects, 16 common principles of microservice design and Governance
MongoDB索引 (3)
Why did I choose the test when the development salary was high?
Verilog的时间系统任务----$time、$stime、$realtime
C language: Little Lele and Euclid



