You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
561 B
28 lines
561 B
// 引入express
|
|
const express = require("express");
|
|
|
|
const fs = require("fs")
|
|
|
|
// 创建网站服务器
|
|
const app = express();
|
|
|
|
app.get("/index",(req,res)=>{
|
|
throw new Error("为止服务器错误")
|
|
})
|
|
|
|
app.get("/",(req,res,next)=>{
|
|
fs.readFile("./05.js",(err,r)=>{
|
|
if (err!=null){
|
|
next(err)
|
|
}else {
|
|
console.log(r.toString())
|
|
res.send(r.toString())
|
|
}
|
|
})
|
|
})
|
|
|
|
app.use((err,req,res,next)=>{
|
|
res.status(500).send("服务器出现错误"+err)
|
|
})
|
|
// 开启服务器监听
|
|
app.listen(80); |