NodeJS错误出现“找不到正文解析器”

时间:2019-05-27 07:03:36

标签: node.js express

当我尝试使用nodemon命令运行NodeJs代码时。该错误表明找不到body-parser。但是我在app.js中包括了body-parser的要求。但是同样的错误一遍又一遍

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

app.use(bodyParser.json());

trainInfo = require('./models/trainInfo');

mongoose.connect('mongodb://localhost/traindb');
var db = mongoose.connection;

app.get('/', function(req, res) {
res.send('Hello world');
});

app.get('/api/trainInfo', function (req, res) {
trainInfo.getTrainInfo(function (err, trainInfo) {
    if(err){
        throw err;
    }
    res.json(trainInfo);
  });
});

app.listen(3000);
console.log('Running on port 3000...');

0 个答案:

没有答案