node创建一个http服务——代码块
作者:ailion
发布时间:2022-07-15 10:04
0人已阅读
简介:
const express = require("express")
const app = express()
const http = require('http')
const fs = require('fs')
const path = require('path')
const port = 3000
app.use(express.static(path.resolve(__dirname, './dist')))
app.get('*', function(req, res) {
const html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8')
res.send(html)
})
http.createServer(app).listen(port,()=>{
console.log(`服务器正在运行http://localhost:${port}`);
})