diff options
Diffstat (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing')
5 files changed, 62 insertions, 0 deletions
diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/README.md b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/README.md new file mode 100644 index 0000000..fc709a3 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/README.md @@ -0,0 +1,6 @@ + +To run: + +- Execute `npm install` from this directory +- Execute `node app.js` +- Navigate to `localhost:8000` diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/app.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/app.js new file mode 100644 index 0000000..8fb2fee --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/app.js @@ -0,0 +1,17 @@ + +var express = require('express'); +var mongoose = require('../../../lib'); + +var uri = 'mongodb://localhost/mongoose-shared-connection'; +global.db = mongoose.createConnection(uri); + +var routes = require('./routes'); + +var app = express(); +app.get('/', routes.home); +app.get('/insert', routes.insert); +app.get('/name', routes.modelName); + +app.listen(8000, function() { + console.log('listening on http://localhost:8000'); +}); diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/modelA.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/modelA.js new file mode 100644 index 0000000..78f9ff6 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/modelA.js @@ -0,0 +1,5 @@ +var Schema = require('../../../lib').Schema; +var mySchema = Schema({name: String}); + +/* global db */ +module.exports = db.model('MyModel', mySchema); diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/package.json b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/package.json new file mode 100644 index 0000000..e326165 --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/package.json @@ -0,0 +1,14 @@ +{ + "name": "connection-sharing", + "private": "true", + "version": "0.0.0", + "description": "ERROR: No README.md file found!", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { "express": "3.1.1" }, + "repository": "", + "author": "", + "license": "BSD" +} diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/routes.js b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/routes.js new file mode 100644 index 0000000..35e4f8f --- /dev/null +++ b/common/src/main/webapp/usageguide/appserver/node_modules/mongoose/examples/express/connection-sharing/routes.js @@ -0,0 +1,20 @@ + +var model = require('./modelA'); + +exports.home = function(req, res, next) { + model.find(function(err, docs) { + if (err) return next(err); + res.send(docs); + }); +}; + +exports.modelName = function(req, res) { + res.send('my model name is ' + model.modelName); +}; + +exports.insert = function(req, res, next) { + model.create({name: 'inserting ' + Date.now()}, function(err, doc) { + if (err) return next(err); + res.send(doc); + }); +}; |