Skip to content

Tiny service to manage neo4j queries and connections made in koa.js

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

adrianiy/neo4j-service

Repository files navigation

Build & Test GitHub license Version

NEO4J-Service

Small service implementation based on koa framework and jeffijoe boilerplate.

Motivation

Expose a tiny api to manage queries to Neo4j Server.

Published endpoints

  • api/login: POST request that gets connection uri, user and pass from reuqest body. With this credentials we will store a Neo4j driver in service store and return it's identifier
  • api/logout: GET request that receives a driver identificator and remove it from the store
  • api/query: GET request that receives a driver identificator and a query to execute against Neo4j server

Implementation

npm run scripts

There are a few defined run scripts, here's a list of them with a description of what they do. To run them, simply execute npm run <script name> - e.g. npm run dev

  • start: Used by the production environment to start the app. This will run a compiled version, so you need to execute build first.
  • build: Runs the babel CLI to compile the app. Files are emitted to dist/.
  • dev: Runs the app in development mode - uses babel-node to compile on-the-fly. Also uses nodemon to automatically restart when stuff changes.
  • test: Runs tests.
  • cover: Runs tests and collects coverage.
  • lint: Lints + formats the code.

Tip: to pass additional arguments to the actual CLI's being called, do it like in this example:

For npm:

# Note the `--` before the actual arguments.
npm run test -- --debug

For yarn:

# Yarn does not need the `--` before the actual arguments.
yarn test --debug

docker-compose up scripts

For running dev:

# Note: use --build only when you want to build. Usually when you change packages.json
docker-compose up --build

For running test:

docker-compose -f docker-compose.test.yml up

Environment variables

The environment variables can be reached by importing lib/env.

import { env } from '../lib/env'

Additionally, all environment variables you'd usually find on process.env will be available on this object.

When attempting to access a key (env.PORT for example), if the key does not exist an error is thrown and the process terminated.

In the repository root, you will find a env.yaml, which is where you can set up environment variables so you won't have to do it from your shell. This also makes it more platform-agnostic.

The top-level nodes in the YAML-file contain a set of environment variables. yenv will load the set that matches whatever NODE_ENV says.

I've set it up so anything in tests will override anything in development when running tests.

Actual environment variables will take precedence over the env.yaml file!

See the yenv docs for more info.

API endpoints

Each file in /routes exports a "controller" that awilix-koa will use for routing. Please see awilix-koa docs for more information.

Dependency injection

This boilerplate uses the Awilix container for managing dependencies - please check out the Awilix documentation for details. The container is configured in lib/container.js.

Middleware

Middleware is located in the middleware folder and is not automatically loaded - they should be installed in lib/server.

Author

License

MIT.

About

Tiny service to manage neo4j queries and connections made in koa.js

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •