This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the default mongodb driver with mongoose. Updated readme
- Loading branch information
Showing
10 changed files
with
56 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
var express = require('express'), | ||
mongoose = require('mongoose'), | ||
fs = require('fs'), | ||
config = require('./config/config'); | ||
|
||
mongoose.connect(config.db); | ||
var db = mongoose.connection; | ||
db.on('error', function(){ | ||
throw new Error('unable to connect to database at ' + config.db); | ||
}); | ||
|
||
var models_path = __dirname + '/app/models'; | ||
fs.readdirSync(models_path).forEach(function(file){ | ||
if(file.indexOf('.js') >= 0){ | ||
require(models_path + '/' + file); | ||
} | ||
}); | ||
|
||
var app = express(); | ||
|
||
require('./config/express')(app, config); | ||
require('./config/routes')(app); | ||
|
||
app.listen(config.port); | ||
app.listen(config.port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
var mongoose = require('mongoose'), | ||
Article = mongoose.model('Article'); | ||
|
||
exports.index = function(req, res){ | ||
|
||
res.render('home/index', { | ||
title: 'Generator-Express MVC', | ||
}); | ||
Article.find(function(err, articles){ | ||
if(err) throw new Error(err); | ||
res.render('home/index', { | ||
title: 'Generator-Express MVC', | ||
articles: articles | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
// Example model | ||
|
||
var MongoClient = require('mongodb').MongoClient, | ||
Db = require('../../config/database'); | ||
var mongoose = require('mongoose'), | ||
Schema = mongoose.Schema; | ||
|
||
module.exports = new Article(); | ||
var ArticleSchema = new Schema({ | ||
title: String, | ||
url: String, | ||
text: String | ||
}); | ||
|
||
function Article(){ | ||
this.collection_name = "articles"; | ||
} | ||
|
||
Article.prototype.findAll = function(callback){ | ||
Db.getCollection(this.collection_name, function(collection){ | ||
collection.find().toArray(function(err, items){ | ||
items.forEach(function(item){ | ||
item.date = getDate(item._id); | ||
}); | ||
callback(items); | ||
}); | ||
ArticleSchema.virtual('date') | ||
.get(function(){ | ||
return this._id.getTimestamp(); | ||
}); | ||
}; | ||
|
||
mongoose.model('Article', ArticleSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
module.exports = { | ||
root: require('path').normalize(__dirname + '/..'), | ||
app: { | ||
name: 'Application-name' | ||
name: '<%= _.slugify(appname) %>' | ||
}, | ||
port: 3000, | ||
db: 'mongodb://localhost/database-name' | ||
db: 'mongodb://localhost/<%= _.slugify(appname) %>' | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters