I need to create a web service and I am using Node.js in server. But when I am running in localhost I am getting an error:
Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
neo4jtest.js
var config = require('./config');
var bodyParser = require('body-parser');
var app = express();
var neo4jurl = process.env.NEO4J_URL ;
neo4jurl = neo4jurl +'/db/data/';
var query = [ 'START me=node:node_auto_index(name={inputusername}) MATCH me<--friend<--friend_of_friend where (friend_of_friend.entitytype={inputentitytype}) RETURN friend_of_friend;' ];
var insertquery = [ 'CREATE (user {entitytype:{inputentitytype}, name : {inputname}}) return user;' ];
var queryforallrelation = [ 'start n = node:node_auto_index(name={inputusername}) match(n)--(x) return x;'];
// Config
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
// configure stuff here
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}
app.get('/api', function (req, res) {
res.send('REST API is running');
});
app.get('/friendoffriend/:username', function (req, res){
res.set({'Content-Type': 'text/json'});
username = req.params.username;
type = 'user';
neo4j.connect(neo4jurl, function (err, graph) {
graph.query(query.join('\n'), {inputusername : username, inputentitytype :type} ,function (err, results) {
if (err) {
res.send(HTTPStatus.INTERNAL_SERVER_ERROR,'Internal Server Error');
}
else {
res.send(HTTPStatus.OK,JSON.stringify(results));
}
});
});
});
app.get('/insertuser/:username', function (req, res){
res.set({'Content-Type': 'text/json'});
username = req.params.username;
type = 'user';
neo4j.connect(neo4jurl, function (err, graph) {
graph.query(insertquery.join('\n'), {inputname : username, inputentitytype :type} ,function (err, results) {
if (err) {
res.send(HTTPStatus.INTERNAL_SERVER_ERROR,'Internal Server Error');
}
else {
res.send(HTTPStatus.OK,JSON.stringify(results));
}
});
});
});
//Cypher Query with Javascript Callback Example
function neo4jQuery(neo4jurl, query, parameters, giveresults) {
neo4j.connect(neo4jurl, function (err, graph) {
graph.query(query.join('\n'), {inputusername : 'andrew'} ,function (err, results) {
if (err) {
giveresults(HTTPStatus.INTERNAL_SERVER_ERROR);
}
else {
giveresults(JSON.stringify(results));
}
});
});
}
app.get('/allrelations/:username', function (req, res){
res.set({'Content-Type': 'text/json'});
username = req.params.username;
parameters = {inputusername : username};
neo4jQuery(neo4jurl, queryforallrelation, parameters, function(results){
res.send(results);
});
});
app.listen(1212);
Following is the error that i got from the console:
C:\node\NodejsNeo4j1-master>node neo4jtest.js Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware. at Function.Object.defineProperty.get (C:\node\NodejsNeo4j1-master\node_modules\express\lib\express.js:89:13) at Object.<anonymous> (C:\node\NodejsNeo4j1-master\neo4jtest.js:26:18) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3