Trouble with reading nodes with node-neo4j & Debugging skills with neo4j-shell - node.js

I'm new to Neo4J. So far, I successfully installed and started the Neo4J server and I checked it by running the command neo4j status.
By using node-neo4j driver to add & update nodes to the database.
In my nodejs server, I create a new database:
db = new neo4j("http://127.0.0.1:7474");
Next, I insert a new node:
db.insertNode( {"name": "Darth Vader","sex": "male"}, (err, node) ->
if err then throw err
console.log "Insert node"
console.log node
)
I face no error when inserting a new node. However, when I try to read this node
db.readNode( {"name": "Darth Vader"}, (err, node) ->
if err then throw err; # 48th line of server.js
console.log "Read node"
console.log node
)
ReadNode function throws the following exception at 48th line( you can find the 48th line at the code snippet given above).
server.js:48
throw err;
^
Error: HTTP Error 500 occurred while reading a node.
at node_modules/node-neo4j/main.js:151:15
at Request.callback (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:656:3)
at Request.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:131:10)
at Request.emit (events.js:95:17)
at IncomingMessage.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:802:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:929:16
at process._tickCallback (node.js:419:13)
Then, I tried to debug my process by checking my database and tried neo4j-shell and typed dbinfo on the command line, I expected to see my database and the Darth Vader node that already inserted.
However, dbinfo returns nothing at all!
How can I find my databases, and nodes in this database with neo4j-shell?
How can I make sure that I successfully inserted the node? How can I read the node that I already inserted?
Do you have any idea?
Thank you in advance!

To make things clear: There are two node-neo4j version out there:
https://github.com/philippkueng/node-neo4j
https://github.com/thingdom/node-neo4j
You are using the philippkueng version: db.readNode will work with nodeId's only. I think you should use db.cypherQuery() with a cypher statement instead for querying the neo4j database.
For example:
db.cypherQuery('MATCH (n {name: "Darth Vader"}) RETURN n',
function(err, result){
if(err) throw err;
console.log(result.data); // delivers an array of query results
console.log(result.columns); // delivers an array of names of objects getting returned
});
Is you want to use labels and indexes without Cypher to lookup the node you could use this:
// add Darth Vader with the label Person
db.insertNode( {name: 'Darth Vader',sex: 'male'}, 'Person',
function(err, node) {})
db.readNodesWithLabelsAndProperties('Person', {name: 'Darth Vader'},
function (err, result) {})
For debugging as #codewithcheese already mentions use the Neo4j browser at:
http://localhost:7474

Related

Random occurrences of Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1 when running protractor tests

My protractor test cases randomly fail with this error message:
Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1
I have gone through the resources and tried all the suggested solutions:
Upgraded protractor
Ran webdriver-manager update
Upgraded chromedriver version but the issue seems to exist.
This particularly happens when I try to run all the e2e tests together.
Below is the specific versions that Im using for my project:
node - v9.2.0
protractor - Version 5.4.1
ChromeDriver 2.42.591088
Please help.
Thanks,
Neeraja
Are you using async/await in your tests?
Can you try applying patch as specified below from the same folder which contains the 'node_modules' folder by executing 'node patch.js'?
patch.js file
var fs = require('fs');
var httpIndexFile = 'node_modules/selenium-webdriver/http/index.js';
fs.readFile(httpIndexFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`)
fs.writeFileSync(httpIndexFile, result, 'utf8');});
var chromeFile = 'node_modules/selenium-webdriver/chrome.js';
fs.readFile(chromeFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`)
fs.writeFileSync(chromeFile, result, 'utf8');});
Please see original post here -
https://github.com/angular/protractor/issues/4706#issuecomment-393004887

The strange Node.js error after starting script

I use Node.js.
My server js script I run such:
node chat_server.js
After I get errors messages in terminal CentOS:
Express server listening on port undefined in development mode.
+ User undefined connected node_redis: no callback to send error: ERR wrong number of arguments for 'sadd' command
/home/who/public_html/node/node_modules/redis/index.js:582
throw err;
^ Error: ERR wrong number of arguments for 'sadd' command
at ReplyParser. (/home/who/public_html/node/node_modules/redis/index.js:317:31)
at ReplyParser.emit (events.js:95:17)
at ReplyParser.send_error (/home/who/public_html/node/node_modules/redis/lib/parser/javascript.js:296:10)
at ReplyParser.execute (/home/who/public_html/node/node_modules/redis/lib/parser/javascript.js:181:22)
at RedisClient.on_data (/home/who/public_html/node/node_modules/redis/index.js:547:27)
at Socket. (/home/who/public_html/node/node_modules/redis/index.js:102:14)
at Socket.emit (events.js:95:17)
at Socket. (_stream_readable.js:748:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:410:10)
Excuse me, but I do not understand the reason of these errors.
On what I should get attention and how fix it?
For example, I use command redis SADD: redis_cli.sadd( "user.friend:" + currentIdUser, data.idUser);
I have done a experiment, created a new text script:
var redis = require("redis");
var client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.sadd("users","naveen",function(err,reply){
console.log('Ok');
if(err)
throw err;
return reply;
});
It have given me in console: OK. It mean, that all works fine.
I think in my code:
redis_cli.sadd("userslist", currentIdUser);
the variable currentUser is simply empty or undefined. It gives me the next errors.
Problem was at my script in line:
redis_cli.sadd("userslist", currentIdUser);
The variable is undefined. It calls error redis.
Thank you all for help.

mongodb connect by mongoskin error

I have tried below mentioned code to connect mongo db using mongoskin node module
var mongo = require('mongoskin');
var db = mongo.db("localhost:27017/mydb");
db.bind('mycollection');
db.mycollection.find().toArray(function(err, items) {
console.log(items)
db.close();
});
I am getting below mentioned error.
/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15
throw Error("URL must be in the format mongodb://user:pass#host:port/dbnam
^
Error: URL must be in the format mongodb://user:pass#host:port/dbname
at Error (<anonymous>)
at exports.parse (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15:11)
at Function.MongoClient.connect (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/mongo_client.js:164:16)
at SkinClass.SkinDb._open (/usr/local/lib/node_modules/mongoskin/lib/db.js:36:25)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.SkinCollection._open (/usr/local/lib/node_modules/mongoskin/lib/collection.js:49:17)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.SkinCursor._open (/usr/local/lib/node_modules/mongoskin/lib/cursor.js:28:25)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.(anonymous function) [as toArray] (/usr/local/lib/node_modules/mongoskin/lib/utils.js:116:14)
In that error it has mentioned enter username and password.I dont have username and pasword.What i have to enter for that please help me.
My mongodb version is v1.8.2,
node version is v0.10.28,
mongoskin version is v1.4.4.
The error says:
throw Error("URL must be in the format mongodb://user:pass#host:port/dbnam")
Have you tried adding the protocol? (i.e.:)
var db = mongo.db("mongodb://localhost:27017/mydb");
The answer lies in the error itself :
throw Error("URL must be in the format mongodb://user:pass#host:port/dbnam
^
Error: URL must be in the format mongodb://user:pass#host:port/dbname
In case you didn't understand , kindly do as mentioned below :
var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/mydb");
db.bind('mycollection');
db.mycollection.find().toArray(function(err, items)
{
console.log(items)
db.close();
});

zombiejs (2.0.0-alpha30) + mochajs (1.17.1) on node 0.10.26

I started working through a book's example code and had the bright idea to update the libraries (node included, from 0.8 -> 0.10). Now there is some breakage & I get this error:
1) Todos Todo creation form should allow to create a todo:
Uncaught Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
I've commented out the assertions to try and locate the issue. It seems like it's a zombiejs centric issue but I'm not sure how to verify that because there are many modules installed as dependencies. There are 10 other tests that pass with most using the login function so I eliminated that from the probabilities. I tried to just post the necessary code snippets. I can provide more if this isn't enough detail. I've found a few stackoverflow posts with this error but the solutions didn't apply. If it turns out to be a zombie issue I will post something on their bug site.
it('should allow to create a todo', login(function (browser, done) {
Browser.visit('http:localhost:3000/todos/new', function (err) {
if (err) throw err;
//browser
// .fill('textarea[name="what]', 'Test todo')
// .pressButton('input[type="submit"]', function (err) {
// if (err) throw err;
//browser.assert.pathname('/todos', 'should be redirected to /todos');
//finish assertions
//browser.assert.elements('#todo-list tr.todo', 1, 'To-Do list should contain 1 item');
//});
});
}));
The main entries in package.json:
"dependencies": {
"union": "0.4.0",
"flatiron": "0.3.x",
"plates": "0.4.x",
"node-static": "0.7.x",
"nano":"5.x.x",
"flatware-cookie-parser" : "0.1.x" ,
"flatware-session": "0.1.x"
},
"devDependencies": {
"mocha" : "latest",
"zombie": "latest"
},
Thanks!!!
Ah, it was a stupid user error. I forgot to tell mocha the test was "done();". I added done to the end of the test case...tests are working as expected. Thanks!

Cassandra driver for nodejs Helenus

I am having problems with cassandra driver for nodejs - helenus. I crated function loop that insert records into table, and I am calling with ab tool. The problem is after 10-20 insert the driver throws error:
This is the coffee code:
helenus = require 'helenus'
pool = new helenus.ConnectionPool(
hosts: ["mybalancer:9160"]
keyspace: "stats"
timeout: 90000
)
pool.on "error", (err) ->
console.error err.name, err.message
pool.connect (err, keyspace) ->
if err
throw (err)
else
vals = [uuid.v4(), uuid.v4()]
#insert_statement = "INSERT INTO test2 (id, name) values(%s, %s)"
console.log(vals)
pool.cql insert_statement, vals, (err, results) ->
console.log err, results
And This is the error:
/home/udev/development/project/U/hubber/app/controllers/event_logger_cassandra.js:98
throw err;
^
HelenusNoAvailableNodesException: Could Not Connect To Any Nodes
at replyNotAvailable (/home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:16:25)
at onConnect (/home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:98:9)
at /home/udev/development/project/U/hubber/node_modules/helenus/lib/pool.js:120:7
at null.<anonymous> (/home/udev/development/project/U/hubber/node_modules/helenus/lib/connection.js:199:5)
at EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (/home/udev/development/project/U/hubber/node_modules/helenus/node_modules/helenus-thrift/lib/thrift/connection.js:56:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:830:16
at process._tickCallback (node.js:415:13)
I have cassandra cluster of three nodes(large servers on amazon) behind load balancer.
I have monitor on the servers and the nodes are always up and work fine.
What do I missing here?
Thanks.

Resources