2.0.1 • Published 7 years ago

zeenix v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Zeenix

An ES2015 Express.js wrapper to quickly spin up a Node.js + MongoDB REST(ish) API.

Prequisities

Installation

Run npm install zeenix

Setup

  1. Create a MongoDB database.

  2. Create a project directory that contains a directory called 'models.'

  3. Set up the following environment variables using your preferred method, e.g. a Procfile.

    • NODE_ENV - development or other (default = development)
    • MONGODB_URI - the URL of your MongoDB database (default = mongodb://localhost)
  4. Create a model in the models directory. Note, the file name will be the name of your collection in the database and URI.

module.exports = {
  create: { // create, update, read, and delete are supported
    new: { // new and newWithID supported for create, one and many supported for read, update, and delete
      customAuth: {
        memberCollection: 'users',
        memberCollectionField: 'facebookID',
        memberField: 'toFacebookID'
      },
      defaultValues: {
        foo: 'bar'
      },
      mutableFields: [
        foo: 'bar'
      ],
      ownersField: 'memberUserIDs', // the name of a field that contains an array of secondary owner userIDs
      preware: function() { // called prior to executing the desired action
        // has access to zeenix methods including this.database, to exit call this.respond or this.next
      },
      postware: function(status, data) { // called after executing the desired action
        // has access to zeenix methods including this.database, to exit call this.respond 
      },
      requiredFields: [
        'foo'
      ],
      requiresAuthentication: false, // requires a valid authorization header, assumed if requiresAuthorization or setOwner is true, not supported by create
      requiresAuthorization: false, // requires a valid authorization header, not supported by create
      setOwner: true // requires a valid authorization header, only supported by create
    }
  }
};
  1. Initialize Zeenix.
let Zeenix = require('zeenix').Zeenix;
new Zeenix();

Filtering

You can filter the data returned by GET requests using the following query parameter structure:

?[field]=[operator]:[value]

Where operator is one of the following:

  • eq - equals (default)
  • ne - doesn't equal

Notes

  • Zeenix logs are only visible if your NODE_ENV is set to 'development.'
  • Zeenix sets the ownerField on all documents created via a POST request.
  • Zeenix uses the accessToken field in the authCollection for auth.
  • Zeenix uses standard HTTP Status codes for all errors.
  • Zeenix uses the '/me' alias in lieu of '/authCollection/:id' and any routes that require authorization.
  • The query parameter 'action' is a reserved, all others are considered filters.

©2017 Robby Marston. All Rights Reserved.

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago