How to post data from module.exports in node.js
<p>I am trying to take a user input and save it to a collection in my database. I am using Node.js, mongodb, mongoose, express.js and ajax. </p>

<p>I am currently trying to take the post when the user submits the form and take the input and save it to my data base from inside of my module.exports in my controller file. </p>

<p>I was able to make this work when all of the code was in one place inside the server.js but in an attempt to break my code apart appropriately I am trying to separate into a MVC system. </p>

<p>My addProductGroup controller looks like this: </p>

<pre><code>//bring in models of data
var groups = require('../models').Groups;
var express = require('express');
var app = express();

//page functions go inside of module.exports
module.exports = {
    index: function(req, res){
        groups.find({}, function(err, groups){
            if(err){
                console.log(err);
            }else{
                res.render('addProductGroup',{title: 'Admin Add Group', adminloggedin: true, subtitle: 'Add a Group', underheaderp: ''});

    app.post('/admin/addProductGroup', function(req,res){
    var newGroupName = req.body.groupname;
    new groupName({
        groupName: req.body.groupname,
    }).save(function(err, doc){
        if(err){
            res.json(err)
        }
        else {
            res.render('addProductGroup',{title: 'Admin ASS Group', adminloggedin: true, subtitle: 'Add a Group', underheaderp: ''});
        }
    });
});
            }
});
    }
}
</code></pre>

<p>My controller is getting my data from my groups collection and then rendering my page. Then when the user posts the data I am trying to make it take the post data, save it to my database and then render the same exact page. I have played a lot with the nesting of my functions and order of operations. </p>

<p>My groups.js Model :</p>

<pre><code>var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var GroupsSchema = new Schema ({
    groupName: String
});

module.exports = mongoose.model('groups', GroupsSchema);
var groupName = module.exports;
</code></pre>

<p>I am using a handlebars template for my views. </p>

<p>So is having all of this in my module.exports a possible thing to accomplish?
Do i need to try and write a function outside of my module.exports to make this work? 
If you need to see any of my other files just let me know.
Any help is greatly appreciated. </p>