November 2017
Intermediate to advanced
298 pages
7h 10m
English
This file is pretty much the same one from the last chapter but we will be making a few changes to eliminate caching:
'use strict'const bodyParser = require('body-parser')const express = require('express');const mongo = require('mongodb')const DB_NAME = 'word_database';const DB_HOST = process.env.DB_HOST || 'localhost:27017';const COLLECTION_NAME = 'words';const SERVER_PORT = 8000;const app = express();const client = mongo.MongoClient();const dbUri = `mongodb://${DB_HOST}/${DB_NAME}`;app.set('view engine', 'pug')app.use(bodyParser.urlencoded({ extended: false }))function loadWordsFromDatabase() { return client.connect(dbUri).then((db) => { return db.collection(COLLECTION_NAME).find({}).toArray(); }) .then((docs) => { return docs.map(doc ...Read now
Unlock full access