FurkanO FurkanO - 1 year ago 70
Node.js Question

Where to put create constraint statements for neo4j in nodejs(express) ?

I am trying to understand how to organize my node api code using neo4j as a db. I am using neo4j-javascript-driver.

I am trying to create constraints on some user fields. But I am not sure where to put the code. Because these create constraint statements should run only once. I thought of manually running statements on neo4j UI where you can run statements, but what if I go production, where I might not want to have to run statements again.

My code :

.then((result) => {
console.log("neo4j constraints successful");
.catch((error) => {
console.log("constraint.js error : ",error);

Answer Source

You could consider running these constraint queries as part of the deployment process. How are you deploying Neo4j? If you are doing it in some automated way (such as Ansible or Docker) you could have a Cypher script file that contains all these Cypher constraint queries and run this script after Neo4j has been successfully started using neo4j-shell.

Alternatively you could simply run these statements every time your application is started. If the constraints already exist there isn't really any harm from running the statements again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download