摘要: 利用 Express 托管静态文件 官方介绍 express.static(root, [options]) app.use(express.static('public')) 示例 /* 托管静态文件 可以指定虚拟目录 可以指定多个目录作为静态资源目录 */ const express = req 阅读全文
posted @ 2020-10-15 16:07 mrtransition 阅读(128) 评论(0) 推荐(0)
摘要: Node.js的Web开发相关的内容: Node.js不需要依赖第三方应用软件(Apach),可以基于API自己实现 实现静态资源服务器 路由处理 动态网站 模板引擎 get,post参数传递和处理 Web开发框架:express封装了以上功能 Express 1.官网 2.安装 $ npm ins 阅读全文
posted @ 2020-10-15 16:01 mrtransition 阅读(89) 评论(0) 推荐(0)
摘要: 使用模板引擎:art-template 安装 npm install art-template --save myserver.js /* 动态网站开发示例 mini版成绩查询功能 使用模板引擎 */ const http = require('http'); const path = requir 阅读全文
posted @ 2020-10-14 15:40 mrtransition 阅读(126) 评论(0) 推荐(0)
摘要: 登录验证 username:admin password:123456 myserver.js /* 登录验证:admin,123456 */ const http = require('http'); const url = require('url'); const querystring = 阅读全文
posted @ 2020-10-14 14:24 mrtransition 阅读(84) 评论(0) 推荐(0)
摘要: 示例:简易版成绩查询 myserver.js /* 动态网站开发示例 mini版成绩查询功能 */ const http = require('http'); const path = require('path'); const fs = require('fs'); const querystr 阅读全文
posted @ 2020-10-14 11:49 mrtransition 阅读(93) 评论(0) 推荐(0)
摘要: 方法 /* post参数处理:querystring parse、decode:将字符串转换为对象 stringify、encode:将对象转换为字符串 */ const querystring = require('querystring'); let parm = "foo=bar&abc=xy 阅读全文
posted @ 2020-10-14 10:58 mrtransition 阅读(151) 评论(0) 推荐(0)
摘要: 方法 /* get参数处理 */ const url = require('url'); let str = 'https://www.baidu.com/s?ie=UTF-8&wd=nodejs'; let ret = url.parse(str); console.log("ret",ret); 阅读全文
posted @ 2020-10-14 10:05 mrtransition 阅读(226) 评论(0) 推荐(0)
摘要: 静态资源服务 /* 封装 ss.js */ const path = require('path'); const fs = require('fs'); const mime = require('./mime.json'); exports.staticServer = (req,res,roo 阅读全文
posted @ 2020-09-29 16:25 mrtransition 阅读(113) 评论(0) 推荐(0)
摘要: 优化静态资源 /* 响应完整的页面信息 静态资源读取 */ const http = require('http'); const path = require('path'); const fs = require('fs'); const mime = require('./mime.json' 阅读全文
posted @ 2020-09-29 16:24 mrtransition 阅读(107) 评论(0) 推荐(0)
摘要: 初步实现静态资源 /* 响应完整的页面信息 静态资源读取 */ const http = require('http'); const path = require('path'); const fs = require('fs'); //根据路径读取文件的内容 let readFile = (ur 阅读全文
posted @ 2020-09-29 16:22 mrtransition 阅读(83) 评论(0) 推荐(0)