node 本地静态服务器
直接上代码
const connect = require("connect"); const serveStatic = require("serve-static"); const c = require("child_process"); //打开浏览器 const app = connect(); const port = 5050; const catalog = { "html":"F:\html" } app.use(serveStatic(catalog.html)); app.listen(port); console.log("监听5000端口"); c.exec(`start http://127.0.0.1:${port}`);
静态代码放在F盘下的html文件夹,直接运行程序就能打开资源