JSPM

  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q59067F
  • License ISC

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

Package Exports

  • ernest

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ernest) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ernest

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

Just create a public folder inside your project directory, put your files inside and do this:

var Ernest = require('ernest');
new Ernest(null,__dirname + "/public").listen();    

And your server is running on PORT:80 (http), loading your "public" folder.

If you are trying something bigger:

new (require('ernest'))(db_name,iport,jsonlimt_mb,session_name,session_secret).
listen(otherorigins,key,cert,socketio_redis_port, isocketio_redis_server)
.LoadModules(function(app,dbc,messenger_io,ernest)
{
    app.get("/hi",function(req,res,next) {res.send("Hi, Im Ernest"); }); 

}).Permission_Session(access_mongodb_collection).Static(ipublic).TextOnError('Access Denied').EnableCLI();

Ernest

Creates a new instance of Ernest

db_name

Your mongo DB name(using mongojs name sintax). By default no database.

ipublic

Your public folder. By default the public folder inside ernest node_module. On null set the public folder inside ernest node_module. On "/" request = index.html

iport

The TCP Port you want the server to run(HTTP) By default 80.

jsonlimt_mb

The max size of json body-parser urlencode By default 90Mb

session_name

This is the name parameter for session (string) By default the current date (string)

session_secret

this is the secret parameter for session (string) By default the current date (string)

listen

this function starts the service

allowothersite

If is set(as true) will allow cross site request by default disabled

key

The path to the file ".pem" (key.pem) of ssl certificate. If is set, enables https. By default is undefined and disable https.

cert

The path to the file ".crt" (server.crt) of ssl certificate. If kep aparameter is set, ermest looks for it and enables https. By default is undefined and disable https.

socketio_redis_port

If is set, enables socket_io with redis for asincronic real time communication. this parameter is the port where redis server is running. Dont forget, for using this option you have to start your Redis Server and put these scripts on your header html files:

<script src="/socket.io/socket.io.js"></script>
<script > var socket = io(); socket.on('disconnect', function () { alert('Server unreachable');});

By default is undefined and disable the socket_io system.

isocketio_redis_server

If socketio_redis_port is set, this parameter is the redis server ip. By default, is set as "localhost"

app

The express instance in which is running the server. You can use all the express methods (post,get, use, etc)

messenger_io

Contains the function for emit messages through socket.io. For emiting a new message you can use:

//async
    ...
    ...
    messenger_io.emit(type_msg,content);

type_msg: String. Word the socket.io on client side will be waiting for emition content: String.String that receives socket.io on client site when type_msg is emitted

dbc

The mongo database controller ErnestDB which hace the following methods:

dbc.InsertInCollection (data,collec,function()
{
    res.json({});
})

//inserted by user;
dbc.InsertInCollectionBy (data,collec,insertedBy,function()
{
    res.json({});
});

//find one element by crit in collec
dbc.FindOneInCollection (crit,collec,function(data)
{
    res.json(data);
});	

//find all elements by crit in collec
dbc.FindInCollection (crit,collec,function(data_array)
{
    res.json(data_array);
});				

//find all and return one particular array element in selected documents.
dbc.FindProyectInCollection	(crit,proj,collec,function(data_array)
{
    res.json(data_array);
});						

//find one and return only the selected properties
dbc.FindOneInCollMostrar 	(crit,mostrar,collec,function(data)
{
    res.json(data);
});						

//find all and return only the selected properties
dbc.FindInCollecMostrar	(crit,mostrar,collec,function(data_array)
{
    res.json(data_array);
});						

//update one document that matches crit in the collection collec
dbc.UpdateOneinCollec (crit,set,collec,function()
{
    res.json({});
});				 			

//update one document that matches crit in the collection collec. Save the user in changedBy	
dbc.UpdateOneinCollecBy (crit,set,collec,changedBy,function()
{
    res.json({});
});				

//update many documents that match crit in the collection collec. 
dbc.UpdateManyinCollec (crit,set,collec,function()
{
    res.json({});
});				 			

//delete the documents that match the crit in the collection collec	
dbc.DeleteFromCollection (crit,collec,function()
{
    res.json({});
});				 			

//Find all documents that match the criteria crit, sorts the array of documents and limits the array
dbc.FindSortLimInCollect (crit,order,lim,collec,function(data_array)
{
    res.json(data_array);
});				 	

//Find all documents that match the criteria crit, sorts the array of documents and limits the array
    
dbc.FindSortInCollection (crit,order,collec,function(data_array)
{
    res.json(data_array);
});				 		

//Executes an aggregation on collect
dbc.AggregatetoArray (agg_arry,collec,function(data_array)
{
    res.json(data_arry);
});				 			

//Return all documents distincs on query that match the crit
dbc.GetDistincts (crit,query,collec,function(data_array)
{
    res.json(data_array);
});				 				

//Return all collection names
dbc.getCollectionNames (function(data_array)
{
    res.json(data_array);
});											

//Return the collection mongojs obj
dbc.GetCollection (collec)								

//Renames the collection
dbc.RenameCollection (oldcollec,newcollec,function()
{
    res.json({});
});						

//Creates the collection collec
dbc.CreateCollection (collec,function()
{
    res.json({});
});									

//Drops the collections collec
dbc.DropCollection (collec,function()
{
    res.json({});
});									
    
//Empty the collection collec
dbc.EmptyCollection	(collec,function()
{
    res.json({});
});									

//Erase the collections in Erase Arry
dbc.EraseCollections (erase,function()
{
    res.json({});
});				 					

//Creates a clone of the collection src, with the name dst
dbc.CloneCollection	(src,dst,function()
{
    res.json({});
});									

####access_mongodb_collection Collection where users are stored.

this version with CLI

.EnableCLI();

Show Erenst CLI in console.

CLI Commands

addUser

Add a new user to your login web system.(user, password, propiertis in json format : {"name": "john doe", "age":34, level:33})

deleteUser

Delete a user to your login web system

showUser

Show user info

status

Show Ernest info (port - http / https)

pid

Show Current Ernest PID procces

db

Show current Mongo DB

setdb

Set a Mongo DB

updateUserPassword

Update user password

updateUserProperties

Update User properties

addPagetoUser

Add permission for user access to the a specific page.

####addPagestoUser Add permission for user access to the a many pages, separates by ",".

removePageUser

Remove permission for user access to the a specific page.

createCollection

Create a collection in the current Mongo Db.

deleteCollection

Delete a collection in the current Mongo Db.

collectionExist

Show if collection exits in the current Mongo DB.

Collections

Show all collections in the current Mongo DB.

man

Show Ernest command info.

clear

Clear Ernest CLI.

exit

Stop Ernest an exit Ernest CLI.

README in edition