代码:consthttp=require('http');constexpress=require('express');constapp=express();constport=8088;app.use("/",express.static(__dirname+'/'));//创建服务器http.createServer(app).listen(port,function(){console.log(`服务器启动成功,可以通过http://localhost:${port}/`)});使用方法:1.将数据内容复制到一个JS文件中,如“app.js”;2、将“app.js”文件放在需要作为服务端的目录下,并将文件发送到“public”目录下;3.运行命令“nodeapp.js”,如果没有安装express模块??,运行命令“npminstallexpress”进行安装;4.打开浏览器访问服务器:http://localhost:8088/index.html可以用极简的NodeJs代码实现一个http静态服务器访问结果:
