节点js:仅进入错误块

时间:2015-09-06 01:29:26

标签: mysql node.js express ejs

这是我在安装时由express js生成的app.js:

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  console.log("coming to this use func");
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
    console.log("Dev request sent");
    console.log(err.message);
    res.status(err.status || 500);
    res.render('error', {
    message: err.message,
    error: err
  });
 });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  console.log("testing this function");
  res.status(err.status || 500);
  res.render('error', {
  message: err.message,
  error: {}
  });
 });

// I wrote this code to detect '127.0.0.1:3000/enter' in the url     
// correspondingly fetches questions from the database
app.post('/enter', function(req, res, next) {
console.log("Coming here.");
connection.query('SELECT * from questions_table', function(err, rows, fields) {
if (!err) {
  console.log('The solution is: ', rows);
  var myData = JSON.stringify(rows);
  res.render('display', {myData:rows })
 }
else {
  console.log('Error while performing Query.');
  res.render('display', { title: 'The index page!'})
  } 
 });
});

控件永远不会出现在我编写的块中,而是进入if循环:

if (app.get('env') === 'development')

总是抛出一些错误。前端只是表单提交。我在这做错了什么? 提前谢谢。

0 个答案:

没有答案