Gremlin, Nodejs, & Neo4j

I have Neo4j version 4.x server installed locally.

Is there is a way to connect to it from Nodejs using Gremlin driver?

I have tried this plugin:


but it is old and archived repo. also it seems that it only supports Neo4j version 2.x

I have also tried sub folder "neo4j-gremlin" from TinkerPop repo:


but it lacks of README or any sort of documentation

That gremlin-plugin repo looks quite old, and I would guess even if there was good documentation, it's very unlikely to work with modern versions of Neo4j.

Can you say more about what you're trying to do? Are you trying to migrate a gremlin codebase from another DB to Neo4j? In general, we wouldn't recommend using gremlin at all, preferring cypher for a lot of reasons related to ease of use and performance, so I'm guessing this is more about migration.

1 Like

What I want is to use Neo4J database but using gremlin command from Nodejs code.

So my application is nodejs using Gremlin driver to connect to the graph database, currently it is Amazon Neptune, but I want to be database agnostic by using one of Gremlin's compatible database (Neo4j I believe on of them)

I would love to hear if you found a solution for this.
I'm about to start a node.js project with Neo4j server and would like to use Gremlin queries on it,

No, as I went with different solution. I believe it should be possible but sorry I don't know how.

In general, we wouldn't recommend using gremlin at all, preferring cypher for a lot of reasons related to ease of use and performance

@david.allen I just want to mention that Gremlin isn't just an alternative to Cypher, it's also an interface.

For example, there's software (this list contains some) that works with any gremlin-enabled graph data source. Meaning that if neo4j supports gremlin, then you can use all of this software on your neo4j data!

@amerharb This github issue tracks neo4j 4 gremlin support, you may go upvote / send a PR!

1 Like

Is there any update how we can use neo4j with npm gremlin?

I tried this simple code in node.js and I get 401 for connecting to the DB, where I run the neo4j with docker file as follows:

version: "3.7"

services:
test_neo4j:
container_name: test_neo4j
image: neo4j:latest
restart: always
environment:
- NEO4J_AUTH:neo4j/test
ports:
- 7474:7474
- 7687:7687
volumes:
- {PWD}/neo4j/data:/data - {PWD}/neo4j/logs:/logs
- {PWD}/neo4j/import:/var/lib/neo4j/import - {PWD}/neo4j/plugins:/plugins
Here is the code:

const gremlin = require('gremlin');
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const PlainTextSaslAuthenticator = gremlin.driver.auth.PlainTextSaslAuthenticator;
const Graph = gremlin.structure.Graph;

const dc = new DriverRemoteConnection('wss://localhost:7474/gremlin', { authenticator: new PlainTextSaslAuthenticator('neo4j', 'test') });

const graph = new Graph();
const g = graph.traversal().withRemote(dc);

const { t: { id } } = gremlin.process;
const { cardinality: { single } } = gremlin.process;

/**

  • Create a new vertex with Id, Label and properties
  • @param {String,Number} vertexId Vertex Id (assuming the graph database allows id assignment)
  • @param {String} vlabel Vertex Label
    */
    const createVertex = async (vertexId, vlabel, code, name) => {
    const vertex = await g.addV(vlabel)
    .property(id, vertexId)
    .property(single, 'code', code)
    .property('name', name) // default database cardinality
    .next().catch(err =>{ console.log(err);});

return vertex.value;
};

createVertex('SOF', 'airport', 'SOF', 'Sofia');

It seems to connect somewhat but I get this error:

PS C:\123\neo4j> node .\app.js
Error: write EPROTO 38976:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16) {

errno: 'EPROTO',
code: 'EPROTO',
syscall: 'write'
}
(node:47436) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'value' of undefined
at createVertex (C:\123\neo4j\app.js:27:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5)