From b67a8a67c30c8f0e172450e09f3699fc0b7667e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 2 Jun 2016 16:35:02 +0200 Subject: add and require models/Movie --- index.js | 3 +++ models/Movie.js | 14 ++++++++++++++ models/index.js | 3 +++ 3 files changed, 20 insertions(+) create mode 100644 models/Movie.js create mode 100644 models/index.js diff --git a/index.js b/index.js index 329f86f..91dbd21 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,9 @@ app.use('/hello', function(req, res, next) { // connect to mongodb mongoose.connect('mongodb://localhost/meanapp'); mongoose.connection.once('open', function() { + + app.models = require('./models/index.js'); + console.log("listening on port " + port); app.listen(port); }); diff --git a/models/Movie.js b/models/Movie.js new file mode 100644 index 0000000..ad6dca1 --- /dev/null +++ b/models/Movie.js @@ -0,0 +1,14 @@ +var mongoose = require('mongoose'); + +var MovieSchema = new mongoose.Schema({ + title: { + type: String, + required: true + }, + url: { + type: String, + required: true + } +}); + +module.exports = mongoose.model('movie', MovieSchema); diff --git a/models/index.js b/models/index.js new file mode 100644 index 0000000..7a7f208 --- /dev/null +++ b/models/index.js @@ -0,0 +1,3 @@ +module.exports = { + movie: require('./Movie') +}; -- cgit v1.1-2-g2b99