Giter Site home page Giter Site logo

needer's Introduction

Needer

IM backend MVC framework based on express and socket.io

Install

npm install needer

Usage

app init:

var app = require("needer")();
app.view.config({
    path:"view",//your views path
    template:"ejs" //the template your use,you need require(template)
});
app.model.config({
    path:"models"//your models path
});
app.controller.config({
    port:{http:8000,ws:8080},//your controllers port
    path:{root:"controller",router:"routers",ws:"sockets"}//your controllers rootPath,routerPath,socketsPath
});
app.controller.use("router",{src:"router",url:"/"}); //add a router controller (and its moduleName,url)
app.controller.use("ws",{src:"socket",nsp:""});//add a ws controller (and its moduleName,nsp)
app.start();

all these path config is not necessary, It's depends on you.

like this

app.view.config({
    template:"ejs" //template is must,and then app will search views file in the root path
});

models:

var model = require("needer").Model();
module.exports = function(){
    return new Entity(); // you need export a factory
};
var Entity = function(){
    this.uid = "123-432---000";
    this.psw = "1111";
    this.config = (cb)=>{
    //the config is not necessary but it will help you handle save action easier
    //id is the primary key of this model,now id:"uid" means the primary key or the store filename is 123-432---000
    //keys is the keys you want to save,now will save the uid and the psw,if there is no keys field,It will save all of your model
        model.config.call(this,{
            file:{
                path:"sample/storage",
                id:"uid",
                extra:".json",
                keys:["uid","psw"]
            },
            db:{
                id:"uid",
                type:"mongodb",
                url:"mongodb://localhost:27017/needer",
                collection:"entity",
                keys:["uid","psw"]
            }
        },cb);
    };
    this.saveAll = (cb)=>{
        model.saveToFile.call(this,{},cb)
    };
    this.savepsw = (cb)=>{
        model.updateToFile.call(this,{
            extra:".json",
            id:"uid",
            keys:["mail"]
        },cb)
    };
    this.saveInDB = (cb)=>{
        model.insertToDB.call(this,{},cb);
    };
    // all of these model function like saveToFile,updateToDB should change the context to your model you can use call(this)
};

router controller:

//just like express router
var router = require("needer").Router();
router.get("/",(req,res)=>{
    var app = router.getApp(); // you will get the app information
    var entity = app.model.factory("entity")(); // you can create a model what you have,now we have entity
    res.render("index"); // you can render view
});
module.exports = router;

ws controller

//just like socket.io
var connection = require("needer").WSConnection();
connection.connect((socket)=>{
    console.log("Connect!!");
    var request = connection.requestParser(socket); // you can get the http request information
    socket.on("disconnect",(msg)=>{
        console.log("Quit",msg);
    });
    socket.on("message",(msg)=>{
    });
});
connection.use((socket,next)=>{
    next();
});
module.exports = connection;

there is no docs yet so....

but you can know more about needer in the sample

by the way,this framework is developing,so you know....

anyway,you're welcome to use needer.

needer's People

Contributors

gargous avatar

Stargazers

Sakuraneko avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.