Socket
Book a DemoInstallSign in
Socket

evented.io

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evented.io

Evented.io is a realtime API server.

0.1.4
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Evented.IO

Evented.IO is a Node.JS module that provides a structured way of building RESTful API servers in combination with Websockets (Using Socket.IO) writen in CoffeScript.

The reason why I've created Evented.IO is because I like another framework called MeteorJS, but meteor is a full-stack framework. I needed the flexibility of an express.js server with the ease of use of a MeteorJS Server.

Also, Evented.IO provides a client-server JavaScript API to work with collections in realtime, in Meteor flavor. The API will result familiar to you even if you have used Firebase.

I wanted to construct AngularJS applications and mobile native applications using those kind of API's and being compleit enough to make whatever you want, having all control over your server.

I've used deployd for example, but I don't like the idea of for example, can't login by default using an OAuth provider. You have to figure out how to implement it. Evented.IO is compatible with everything, so you can implement it your way maybe using.... ¿Passport?

That said, let's provide a little of light over the table.

How to Install

In order to instantiate a new server you need to have running an instance of MongoDB and another of a Redis store

Configure a new server

evented = require 'evented.io'

Evented = evented({port: 5000});

Models and Controllers

You should have 2 folders on your server's root directory:

  • 'models' directory
  • 'controllers' directory

Checkout the examples to know how to write new models and controllers to create RESTful routes

Creating a new model

This is not the real User model implementation, we need password salting and those things, but this will give you an idea. Default Modules are loaded into process.modules

This is the default schema for a model.

 # Model Structure

 mongoose = process.modules.mongoose
 validate = process.modules.validate

 animalSchema = mongoose.Schema
  
   name:
      type: String
      required: true
      unique: true
      validate: validate('len', 5, 10)

   kind:
      type: String
      required: true
      enum: ['cat', 'dog']

 # Animal model
 module.exports = mongoose.model('Animal', animalSchema);  

Creating a new controller

 # Animals controller

 Animal = process.server.mongodb.models.Animal

 getAllAnimals =
    method: 'get'
    path: "/animal"
    version: 1 # Here we specify the version http://api.server.com/v1/animals
    description: 'Get all Animals'
    docURL: '/AnimalController#GET_ALL_ANIMAL_ACTION' # Documentation URL
    params:
    	# you can specify required or optional fields
        required: [] 
        optional: []
        
    # Also allowed user kinds and roles
    allowedUserKinds: []
    roles: []
    callback: (req, res, completeCall) ->

        Animal
        .find()
        .exec (err, animals)->

            if err
                return next
                	 # Send this data structure
                    httpStatus: 500 # There was an error
                    metadata: err

            completeCall({animals: animals})
            
 module.exports = ->
 	
 	# Here is where we export our Restfull API's
 	
 	[getAllAnimals]

Custom Databases

To use custom databases into your server do the next thing:

Your node index.js

Evented = evented({
  port: 5000,
  mongo: {
    host: 'localhost'
    password: '27017'
    db: 'testdb'
    user: ''
    password: ''
  },
  redis: {
    host: 'localhost'
    port: '6379'
    password: ''
  }
});

Configure a new client

You should use this two scripts in your header

<head>
	<script src="socket.io/socket.io.js"></script>
	<script src="evented.js"></script>
</head>

TODO

  • Describe API
  • UserCollection documentation
  • Evented API
  • Collections
  • Pub/Sub
  • process new API's (server, redis, mongoDB, etc...)
  • Evented.Collection
  • Evented.Collections
  • Evented.suscribe
  • Evented.publish

FAQs

Package last updated on 12 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.