Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

What is the best practice ? (beginner question) #34

k33g opened this Issue Jun 3, 2012 · 0 comments


None yet
1 participant

k33g commented Jun 3, 2012

I wish I knew what was best if I make an application with Express (for example) :

  • i need a "model"
  • i need to save each instance of model

do I have to, every time I save, do a :

var mystore = nStore.new("data/blog.db", function() {
    mystore.save(null, myModel, function(err, key){ ... });

or I declare, initially, a global variable (for example) then I use in my modelsUndo edits :

global.blogStore = nStore.new("data/blog.db", function() {
    app.get('/add',function(req, res){

        var model_from_client = JSON.parse(req.param("model", null));       
        var post = new Post(model_from_client.title, model_from_client.message);

            console.log("Post added with key : ", key)


    console.log('Express app started on port 3000');    

and with :

var Post = function (title, message) {
    this.title = title ? title : "";
    this.message = message ? message : "";

    this.save = function(callback) {
        blogStore.save(null,this,function(err, key){
            callback(key, err);

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment