cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j from JavaScript

Hi All,

I am a student trying to build a web application using neo4j as the back end. I would like to connect my front end, in which I am using HTML and javaScript to connect to neo4j, but I'm having trouble understanding and following the instructions given here: https://neo4j.com/developer/javascript/ successfully.

I am using mac and also having trouble installing node.js and npm via my terminal.

I have no prior experience in this, I would be grateful if you could help me.
Thanks!

3 REPLIES 3

One way could be just Neo4j REST APIs using jquery etc from your UI..
URL: http://localhost:7474/db/data/transaction/commit
Method: post
Add Authorization header with Basic token
body

{
    "statements":
      [{
        "statement": "<query as string>"
      },
      "parameters" : {
      "country" : "es"
      }
      ]
  }
$.ajax({
    url: 'http://localhost:7474/db/data/transaction/commit',
    type: 'post',
    data: body,
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic your_basic_auth_token'
    },
    dataType: 'json',
    success: function (data) {
        console.info(data);
    }
});

Use this option only for learning as your credential could be exposed

Hi

How can get this value, basic token? 'Authorization': 'Basic your_basic_auth_token'

I already look at neo4j desktop, but cant find it.

How can get this value, basic token? 'Authorization': 'Basic your_basic_auth_token'

You can obtain that token by authenticating via basic auth (username and password).
In Neo4J's driver this is accomplished in JS like this:

const neo4j = require('neo4j-driver')
neo4j.auth.basic(user, password)

You can find the documentation here:
js-driver-authentication

Regarding npm / nodejs installation:
You can find install binaries directly on nodejs.org

As a suggestion I would rely on using a framework like express to create a basic API for the frontend based on your requirements.

You can then call your own http(s) routes and leave Neo4J and authentication in the backend.