learning express step(十四)

learning express error handle

code:

const express = require('express');
const app = express();
const fs = require('fs');

app.get('/', function (req, res, next){
   fs.readFile('file', function (err, data) {
      if(err){
         next(err)
      }else{
         res.send(data);
      }
   });
});

app.listen(3000);

result:

 

posted @ 2019-06-13 11:30  嵌入式实操  阅读(75)  评论(0编辑  收藏  举报