Node学习(二) --使用http和fs模块实现一个简单的服务器
2024-09-07 06:15:57
1.创建一个www目录,存储静态文件1.html、1.jpg。
* html文件内容如下:
1 |
<html lang="en"> |
预期实现的结果为:
a. 在浏览器访问http://localhost:8080/1.html
。
b. 读取到www/1.html
,由HTML
文件发起对www/1.jpg
的请求。
c. 网页中显示HTML
内容和图片。使用Nodejs实现服务端代码:
1 |
const http = require('http') |
服务器需要具备的基本功能
1.响应请求
如上面的例子,可以根据客户端的请求做出回应,如返回静态文件。
2 数据交互
定义接口,客户端根据接口,与服务端进行数据交互。
例如在一个购物流程中,客户端向服务端请求商品数据,展现给客户,客户在购买时,客户端将购买的商品信息发送给服务端处理。
数据库
3.对数据库中存储的数据进行读写操作。
最新文章
- Source Insight 3.X utf8支持插件更新
- ios推送:本地通知UILocalNotification
- DataSanp的控制老大-DSServer
- 转:JAVA中this用法小结
- java学习——集合框架(泛型,Map)
- charset
- 如何成为一个优秀的DBA
- 数据采集工具Telegraf:简介及安装
- Mysql概念及基本操作
- 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165321
- CodeForces - 1051D-简单DP
- MySQL5.7 编译安装
- kubectl命令自动补全
- C#-1-1-.net
- 几种outofmemory
- [转]Apache的CRT格式SSL证书转换成IIS用的PFX格式
- vdbench 数据校验测试方法
- eclipse 打开的时候弹出 &#39;Building workspace&#39; has encountered a problem. Errors occurred during
- The import java.util cannot be resolved
- 【起航计划 024】2015 起航计划 Android APIDemo的魔鬼步伐 23 App->;Notification->;IncomingMessage 状态栏通知