Skip to content

Get the content of a neo4j Cypher file as a string, using the standard require() method

License

Notifications You must be signed in to change notification settings

cybersam/require-cypher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

require-cypher

Enables you to get the content of a Cypher file as a string, using the standard require() method.

Every file is cached in a separate node module. As is to be expected with require(), the local file must be must specified using a relative or absolute path.

The supported Cypher file extensions are:

  • .cyp
  • .cql
  • .cypher

NOTE: If you pass a file path to require() not having one of the above extensions, then require() will perform its normal processing.

Basic Example

// keanuLikesLily.cypher
MATCH (keanu:Person), (lily:Person)
WHERE keanu.name = 'Keanu Reeves' AND lily.name = 'Lilly Wachowski'
MERGE p=(keanu)-[:LIKES]->(lily)
RETURN p;
require('require-cypher'); // Registers handlers for supported Cypher file extensions

// Get contents of keanuLikesLily.cypher as a string, using standard require() method
var query = require('./keanuLikesLily.cypher');

Sample app

The example folder contains an app that demonstrates handling of all supported extensions, and also of a couple of errors (file not found, and file does not have a supported extension). When require() throws an error, it will log its own error messages as well.

You can execute the sample app using either node example or npm run example.

To get array of supported Cypher file extensions

// This is the only scenario in which client needs to use the 'require-cypher' module directly
var requireCypher = require('require-cypher');
var extensions = requireCypher.supportedFileExtensions;