Configuration

Overview

We want to make it simple and configurable so then you don't need to write additional logic.

Standalone server

Configuration files are based in ./config/ directory. The main configuration file is root.json.

Below is example of configuration:

{
  "elasticsearch": {
    "host": "localhost:9200",
    "log": "error"
  },
  "redis": {
    "host": "127.0.0.1",
    "port": 6379,
    "auth_pass": null
  },
  "server": {
    "host": "http://127.0.0.1",
    "port": 3000
  },
  "collections": {
    "db": "json",
    "filename":  "./config/collections.json"
  }
}
{
  "collections": {
    "db": "json",
    "filename":  "./config/local/my-local-collections.json"
  }
}

NPM server

var itemsapi = require('itemsapi');

itemsapi.init({
  server: {
    port: 5000
  },
  collections: {
    db: 'json',
    filename:  './collections.json'
  },
  elasticsearch: {
    host: 'localhost:9200'
  }
})

You can even extend express.js to make additionals endpoints i.e. yourdomain.com/about-us:

var itemsapi = require('./server');
itemsapi.init({})

// standard express syntax
var express = itemsapi.get('express');
express.get('/about-us', function(req, res) {
  res.json({
    name: 'itemsapi',
    license: 'MIT'
  });
});
Was this page helpful ?