{"id":17238043,"url":"https://github.com/jsantell/swag-mvc","last_synced_at":"2025-03-26T02:16:04.268Z","repository":{"id":3554910,"uuid":"4615926","full_name":"jsantell/swag-mvc","owner":"jsantell","description":"connecting your models and routes in node.js","archived":false,"fork":false,"pushed_at":"2012-07-21T19:27:42.000Z","size":113,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T23:35:58.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kashifmin/KashKernel_MT6589","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsantell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-10T15:10:38.000Z","updated_at":"2017-03-04T06:06:12.000Z","dependencies_parsed_at":"2022-08-20T19:51:01.159Z","dependency_job_id":null,"html_url":"https://github.com/jsantell/swag-mvc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsantell%2Fswag-mvc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsantell%2Fswag-mvc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsantell%2Fswag-mvc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsantell%2Fswag-mvc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsantell","download_url":"https://codeload.github.com/jsantell/swag-mvc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245573893,"owners_count":20637674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T05:44:29.794Z","updated_at":"2025-03-26T02:16:04.241Z","avatar_url":"https://github.com/jsantell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"swag-mvc\n======\n\nconnecting your models and routes in node.js\n\n### Installing\n\n* `npm install swag-mvc`\n\n### Creating\n\n* `var mvc = require('mvc')( app )` Pass in `express.createServer()`\n\n### Models\n\n* `mvc.initModels( models, dir, setupFunction, args )` sets up models in `dir` defined in the array of strings `models`. `setupFunction` has two arguments, one is the capitalized name of the model and the other is the return value of the model file in `dir/ModelName` to hook it into your database of choice. `args` are arguments passed into the model file.\n\n### Routes\n\n* `mvc.initRoutes( routes, dir, args )` sets up the routes in `dir`, defined with an array of strings `routes`, passing in `app`, corresponding model if applicable, followed by additional `args`.\n\nExample\n---\n`app.js`\n```javascript\n  mvc = require('mvc')( app );\n  db  = mongoose.connect( url );\n\n  mvc.initModels( [ 'User' ], __dirname + '/models/', function ( name, schema ) {\n    db.model( name, schema );\n    return db.model( name );\n  }, {\n    mongoose: mongoose\n  });\n\n  mvc.initRoutes( [ 'users', 'pages', 'sesions' ], __dirname + '/controllers/', {\n    auth: function ( req, res, next ) {\n      req.isAuthenticated() ? next() : res.redirect( '/login' );\n    });\n  });\n```\n\n`ROOT/controllers/users.js`\n```javascript\n  // Passing in arguments app, the model, and arguments object passed in\n  // during initRoutes\n  module.exports = function ( app, User, args ) {\n    app.get( '/users', function ( req, res, next ) {\n      User.find( {}, ( err, users ) {\n        if ( !err ) { res.render( 'users/index', { users: users } }\n      });\n    });\n\n    app.get( '/register', function ( req, res, next ) {\n      res.render( '/users/new' );\n    });\n  };\n```\n\n`ROOT/models/User.js`\n```javascript\n  module.exports = function ( args ) {\n    mongoose = args.mongoose;\n    ObjectId = mongoose.SchemaTypes.ObjectId;\n\n    UserSchema = new mongooose.Schema({});\n\n    // this is the schema passed into the\n    // setupFunction in initModels\n    return UserSchema;\n  };\n```\n\nTesting\n---\n\nRun `node tests/runTests.js` from project root -- testing uses `nodeunit`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsantell%2Fswag-mvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsantell%2Fswag-mvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsantell%2Fswag-mvc/lists"}