With the model defined, you can begin implementing the web application server. Listing 29.2 implements the Express server for the web application. This code should be familiar to you. It includes the express
and mongoose
libraries and connects to the MongoDB words
database via Mongoose.
Notice that there is a require('./models/word_model.js')
statement for the model definition to build the Schema
object within Mongoose. Also, the ./rich_ui_routes
files initialize the routes for the server before listening on port 80.
Listing 29.2 rich_ui_server.js
: Implementing the web application server using Express and connecting to MongoDB
01 var express = require('express'),
02 var bodyParser = require('body-parser'),
03 var mongoose = require('mongoose'),
04 var db = mongoose.connect('mongodb://localhost/words'),
05 require('./models/word_model.js'),
06 var app = express();
07 app.engine('.html', require('ejs').__express);
08 app.set('views', __dirname + '/views'),
09 app.set('view engine', 'html'),
10 app.use(bodyParser());
11 require('./rich_ui_routes')(app);
12 app.listen(80);
52.14.136.168