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.
// 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');
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
.
// 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;