hello大家好,最近太忙好久没发文章了,大家还记得我吗?
今天我有带来了新鲜的代码,一起来看看吧。
今天我来教大家如何创建新的服务器进程,可以用到两种工具第一种是cmd,第二种是node.js,废话不多说我们开始吧!
我先教大家用cmd创建服务器进程。用cmd创建服务器进程也需要用到node.js,请先安装好node.js,如果没有下载可以在Node.js — Download这个网站中下载,下载完后在cmd输入
npm pip install http-server
npm pip install http-server(下载http-server)
接下来输入
http-server/8080
http-server/8080(8080是端口可以不写因为默认端口就是8080)
等待后即可创建服务器进程
node.js的方法就是先下载node.js
然后输入
// 导入http模块
const http = require('http');
// 定义端口号
const port = 3000;
// 创建服务器
const server = http.createServer((req, res) => {
// 设置响应头
res.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应
res.end('Hello World')});
// 监听端口
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`)});
本期讲解结束,谢谢观看