安装
mkdir [项目名]
cd [项目名]
npm init -y
安装依赖
npm i -S express
创建app.js
const express = require('express')
const app = express()
app.get('/', function(req, res) {
throw new Error('err....')
res.send('heellp')
})
function errorHandler(err, req, res, next) {
console.log(err)
res.status(500).json({
error: -1,
msg: err.toString()
})
}
app.use(errorHandler)
const server = app.listen(5000, function() {
const {address, port} = server.address()
console.log('http server is running on http://%s:%s', address, port)
})
网友评论