当前位置:网站首页>meime module
meime module
2022-08-02 03:39:00 【cjx177187】
var re=mime.getExtension("text/css")
console.log(re)====>prints text typecss
var re2=mime.getType("1.jpg")
console.log(re2)=====>返回jpg
mime.getExtension===>返回类型
mime.getType=====>返回文件类型
var url=require("url")
var querystring=require("querystring")
var http=require("http")
var fs=require("fs")
var app=http.createServer((req,res)=>{
let urlobj=url.parse(req.url)
let pathname=urlobj.pathname
if(pathname=="/"){ pathname="/index.html"}
let path=__dirname+"/src"+pathname
console.log(111111111111,path)
fs.readFile(path,(err,data)=>{
if(!err){
res.setHeader("content-Type","text/html")
res.end(data)
}
else if(pathname=="/login"){
let queryobj=querystring.parse(urlobj.query)
console.log(queryobj)
//Send the data from the front end 去处理
res.end("hello")
}
else if(pathname=="/car"){
res.end("666666car")
}
else {
res.end("404 not found")
}
})
})
app.listen(8080)
代码优化,引入mime
利用mime中的getTypeReturns the type of file to use insteadsetHeader中的文本类型,Any file can be read correctly
var mime=require("mime")
var url=require("url")
var querystring=require("querystring")
var http=require("http")
var fs=require("fs")
var app=http.createServer((req,res)=>{
let urlobj=url.parse(req.url)
let pathname=urlobj.pathname
if(pathname=="/"){ pathname="/index.html"}
let path=__dirname+"/src"+pathname
console.log(111111111111,path)
fs.readFile(path,(err,data)=>{
if(!err){
let type1=mime.getType(path)
res.setHeader("content-Type",type1)
res.end(data)
}
else if(pathname=="/login"){
let queryobj=querystring.parse(urlobj.query)
console.log(queryobj)
//Send the data from the front end 去处理
res.end("hello")
}
else if(pathname=="/car"){
res.end("666666car")
}
else {
res.end("404 not found")
}
})
})
app.listen(8080)
边栏推荐
- Chemical reagent Phospholipid-polyethylene glycol-hydroxyl, DSPE-PEG-OH, DSPE-PEG-Hydroxyl, MW: 5000
- 这些JS题面试时一定要答对!
- L1-039 古风排版(C)
- Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
- 错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
- 新工程加载YOLOV6的预训练权重问题
- 微信小程序九宫格抽奖和转盘抽奖的实现
- Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
- meime模块
- AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
猜你喜欢

The querystring module

kettle 安装与配置

yolov5调用ip摄像头时出现的问题

Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields

微信小程序云开发之券码领取,怎么防止用户领取到相同的数据?

STM32 map文件解析

mysql阶段总结

DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine supply, MW: 5000

URL模块

新工程加载YOLOV6的预训练权重问题
随机推荐
【面试】失败的一次面试
相对路径和绝对路径
微信小程序九宫格抽奖和转盘抽奖的实现
docker 安装 sqlserver中的坑点
L1-039 古风排版(C)
clock tick marks
mysql阶段总结
小程序 van-cell 换行能左对齐问题
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
动态代理工具类
新工程加载YOLOV6的预训练权重问题
SOCKS5
debian 10 nat and routing forwarding
---静态页面---
Debian 10 NTP Service Configuration
C语言的变长数组
基本运算符
客户评分控件
nucleo stm32 h743 FREERTOS CUBE MX配置小记录