Imagine, being a fullstack JavaScript developer and not just using the language in the frontend, middleware or backend but also to create your user-defined procedures and functions in the database.

Several other databases support a similar approach for views and user defined extensions, and now you can do it with Neo4j too.

Already early last year, Neo4j’s user defined procedures were still in their infancy. I had just written an article about the Javas JavaScript engine "Nashorn".

So naturally I experimented with using procedures to dynamically create and run JavaScript functions.

The function mapping is stored in Neo4j’s graph properties.

You could create JavaScript functions with a name and body and then later call them by name and passing parameters along.

CALL scripts.function('users', '
function users(name) {
  return collection(db.findNodes(label("User"),'lastname',name));
}')

CALL scripts.run('users','Anderson') YIELD value as user;

// or call as function, returns a list
RETURN scripts.run('users','Smith');

That worked all quite well, but I didn’t find the time to turn that into a proper project.

Later in the year I got some feature and pull requests on the APOC procedure library to add such functions.

As there are some concerns esp. from corporate users about scripting support, I pulled my work into a separate project: Neo4j Script Procedures

So, when I came across this tweet, it reminded me of wanting to update the project.

@rektide Neo4j. I was just toying with it, so perhaps I'm not being fair. But deploying jars for sprocs is a nonstarter.

— Jason Weiler (@jasonweiler) March 28, 2017

I thought it was a good opportunity to upgrade and release the project.

So, now you can try to run JavaScript functions from Neo4j’s Cypher by grabbing the jar-file from the latest release.

Just put it into $NEO4J_HOME/plugins and restart your server.

Note: In Neo4j Community Desktop, there is a directory chooser on the "Options" for the plugins directory)

The 3.1.0.1 of neo4j-script-procedures release does not support Neo4j 3.1.2 as there are some incompatibilities with procedures creating new property-names. It should work with 3.1.0, 3.1.1 or 3.1.3 though.

Let me know what you think and how we can improve this little useful library, please raise issues on the repository for feedback and problems.