ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 4.5静态资源 服务器端不需要处理,可以直接响应给客户端的资源就是静态资源,例如CSS、JavaScript. image文件。 [http://www.itcast.cn/images/logo.png](http://www.itcast.cn/images/logo.png) 基本运行结构 ![](https://img.kancloud.cn/d3/0c/d30cd8acd91693b4955dfed7fd033df9_654x377.png) [CommonJS 模块 | Node.js API 文档 (nodejs.cn)](http://nodejs.cn/api/modules.html#modules_dirname) 静态资源 (页面页面跳转) ![](https://img.kancloud.cn/64/cb/64cb80e07ae5fb67b53211054242264c_984x915.png) 优化 (优化 / 根目录 直接进入指定文件) ![](https://img.kancloud.cn/a2/34/a23421b0cc401b3c7118fa92fe6cff81_1067x706.png) 优化 根据请求的信息分析它的类型 然后返回类型值 `npm install mime` ![](https://img.kancloud.cn/79/80/798037300a420f239efffc3aa9065626_1075x1221.png) ~~~ const http=require('http'); const url=require('url'); const path=require('path'); const fs=require('fs'); const app=http.createServer(); // const qqq=require('querystring'); // app.on('request',(req,res)=>{ // console.log(req.method); // res.end("qqq"); // }); // app.listen(3000); // console.log("appa"); console.log("qq"); app.on('request',(req,res)=>{ let pathname=url.parse(req.url).pathname; let realPath=path.join(__dirname,'京东'+ pathname); console.log(realPath); console.log("pathname"); fs.readFile(realPath,(error,result)=>{ res.end(result) }) }); console.log("11"); app.listen(3000); ~~~