在快速应用程序中获取错误“bodyParser.json不是一个函数”

我是nodejs的新手。 当快递试验时,我卡住了。 我只是想testing我的应用程序。 运行server.js文件时出现错误。 我错过了什么?

这是什么控制台看起来像…

C:\Users\rupindersingh\Dropbox\Works\worthlessmongo>node server.js C:\Users\rupindersingh\Dropbox\Works\worthlessmongo\server.js:12 app.use(bodyParser.json()); ^ TypeError: bodyParser.json is not a function at Object.<anonymous> (C:\Users\rupindersingh\Dropbox\Works\worthlessmongo\server.js:12:20) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:974:3 

这是pakage.json文件

 { "name": "worthlessmongo", "version": "1.0.0", "description": "Just Tryin", "main": "server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node server.js" }, "author": "", "license": "ISC", "dependencies": { "body-parser": "^1.15.2", "ejs": "^2.5.2", "express": "^4.14.0", "mongojs": "^2.4.0" }, "devDependencies": {} } 

Server.js文件如下:

 var express=require('express'); var path=require('path'); var bodyParser=('body-parser'); var index=require('./routes/index'); var app=express(); app.set('views',path.join(__dirname,'views')); app.set('view engine','ejs'); app.engine('html',require('ejs').renderFile); app.use(express.static(path.join(__dirname,'client'))); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:false})); app.use('/',index); app.listen(3000,function(){ console.log('server started at port 3000'); }); 

需要身体分析器时,您没有使用require

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