Just for Node.js & React.js Developers: A New Neo4j Movies Template

Just for #Nodejs & #Reactjs Developers: A New #Neo4j Movies Template


via @thesilverlogic

  • The Front-end: The front-end, in this case is built in React.js, consumes the data presented by the Express.js API and presents some views to the user, including the home page, a Movie detail page and a Person detail page.
  • If you run into problems, make sure your database is actually running and that you’ve entered your database credentials in the api/config.js file.
  • In the app, calls to the database are handled by /api/neo4j/dbUtils.js , described piece by piece below.
  • An array of genres appears at /genres .
  • npm install bower install gulp Over on http://localhost:4000/ , you should see the homepage of the movie app, displaying three featured movies and some members of the Action genre.

Discover this new movies template app designed just for JavaScript developers using Node.js, React.js or Express.js alongside the Neo4j graph database.

@neo4j: Just for #Nodejs & #Reactjs Developers: A New #Neo4j Movies Template

via @thesilverlogic

Let’s jump right into it. You’re a JavaScript developer interested in Neo4j and want to build a web app, microservice or mobile app.

You’ve already read up on Neo4j, played around with some datasets, and know enough Cypher to get going. Now you’re looking for a demo app or template to get the ball rolling – you’ve come to the right place.

The Model: This project uses a classic Neo4j dataset: the movie database. It includes

and

nodes, connected by relationships as described in the following image:

In this example app, every node type and relationship type has its own CSV file. In order to create and view the movie graph:

If you’re on Unix and downloaded the .tar version of Neo4j you should be fine using stock

neo4j-import

If you’re on Mac or Windows and downloaded the .dmg or .exe versions of Neo4j, try replacing the

In order to run the API, you’ll need to open a new terminal tab and move to the

api

directory install dependencies using

npm install

cd api npm install

to manage your version of Node.js (I’m using v6.2.1).

If you run into problems, make sure your database is actually running and that you’ve entered your database credentials in the

With the database and Express.js backend running, open a new terminal tab or window and move to the project’s

Over on http://localhost:4000/, you should see the homepage of the movie app, displaying three featured movies and some members of the

Click on a person to see that person’s related persons and movies the person has acted in, directed, written or produced:

Let’s take a closer look at what sort of responses we get from the JavaScript Bolt driver. In this app, calls to the database are handled by

var nconf = require(‘../config’); var neo4j = require(‘neo4j-driver’).v1; var driver = neo4j.driver(nconf.get(‘neo4j-local’), neo4j.auth.basic(nconf.get(‘USERNAME’), nconf.get(‘PASSWORD’)));

Let’s look at how we would ask the database to return all the genres in the database.

getAll

var _ = require(‘lodash’); var Genre = require(‘../models/neo4j/genre’); var getAll = function(session) { return session.run(‘MATCH (genre:Genre) RETURN genre’) .then(_manyGenres); }; var _manyGenres = function (result) { return result.records.map(r => new Genre(r.get(‘genre’))); }; module.exports = { getAll: getAll };

// extracts just the data from the query results var _ = require(‘lodash’); var Genre = module.exports = function (_node) { _.extend(this, _node.properties); if (this.id) { this.id = this.id.toNumber(); }; }; ;

{ records: Record { keys: [ ‘genre’ ], length: 1, _fields: [ Node { identity: Integer { low: 737, high: 0 }, labels: [ ‘Genre’ ], properties: { name: ‘Suspense’, id: Integer { low: 3270, high: 0 } } ], _fieldLookup: { genre: 0 } }, … // more records ], summary: ResultSummary { statement: { text: ‘MATCH (genre:Genre)\nRETURN genre’, parameters: {} }, statementType: ‘r’, updateStatistics: StatementStatistics { _stats: [Object] }, plan: false, profile: false, notifications: [] } }

genre

node, we would use

{ “name”: “Family”, “id”: 1258 }

The return function parses the messy results into the data we need:

var _manyGenres = function (result) { return result.records.map(r => new Genre(r.get(‘genre’))); };

Voila! An array of genres appears at

Get your free copy of the Learning Neo4j ebook and catch up to speed with the world’s leading graph database.

Just for Node.js & React.js Developers: A New Neo4j Movies Template