├── .gitignore ├── .nvmrc ├── Chapter_01 └── hello-world │ ├── app.js │ └── package.json ├── Chapter_02 ├── mustache │ ├── mustache-test.js │ ├── package-lock.json │ └── package.json └── random-integer │ ├── print-three-random-integers.js │ └── random-integer.js ├── Chapter_03 ├── guestbook │ ├── app.js │ ├── package.json │ └── views │ │ ├── 404.ejs │ │ ├── footer.ejs │ │ ├── header.ejs │ │ ├── index.ejs │ │ └── new-entry.ejs ├── hello-world │ ├── app-morgan-logging.js │ ├── app-simple-logging.js │ ├── app-simple.js │ ├── app.js │ ├── cool-facts.txt │ ├── package.json │ └── route-example.js ├── statics │ ├── app.js │ ├── package.json │ └── public │ │ └── file.txt └── views-example │ ├── app.js │ ├── package.json │ └── views │ └── index.ejs ├── Chapter_04 ├── error-stack │ ├── app.js │ └── package.json └── static-file-fun │ ├── app.js │ ├── first-version.js │ ├── package.json │ └── static │ └── cool.txt ├── Chapter_05 └── temperature-by-zip-code │ ├── app.js │ ├── package.json │ ├── public │ ├── the.css │ └── the.js │ └── views │ ├── 404.ejs │ ├── footer.ejs │ ├── header.ejs │ └── index.ejs ├── Chapter_06 └── random-number-api │ ├── app.js │ └── package.json ├── Chapter_08 └── learn-about-me │ ├── README.md │ ├── app.js │ ├── models │ └── user.js │ ├── package.json │ ├── routes.js │ ├── setuppassport.js │ └── views │ ├── _footer.ejs │ ├── _header.ejs │ ├── edit.ejs │ ├── index.ejs │ ├── login.ejs │ ├── profile.ejs │ └── signup.ejs ├── Chapter_09 ├── simple_tests │ ├── .gitignore │ ├── capitalize.js │ ├── package.json │ └── test │ │ ├── capitalize.js │ │ └── mocha.opts └── whats_my_useragent │ ├── .gitignore │ ├── app.js │ ├── package.json │ ├── test │ ├── html.js │ └── txt.js │ └── views │ └── index.ejs ├── Chapter_10 ├── csrf-example │ ├── app.js │ ├── package.json │ └── views │ │ └── index.ejs ├── forever-example │ ├── app.js │ └── package.json └── print-queries │ ├── app.js │ └── package.json ├── Chapter_11 ├── grunt-examples │ ├── .gitignore │ ├── Gruntfile.js │ ├── app.js │ ├── my_css │ │ └── main.less │ ├── my_javascripts │ │ └── main.js │ └── package.json └── heroku-app │ ├── .gitignore │ ├── Procfile │ ├── app.js │ └── package.json ├── Chapter_12 └── express-generated-app │ ├── .gitignore │ ├── app.js │ ├── bin │ └── www │ ├── package.json │ ├── public │ └── stylesheets │ │ └── style.css │ ├── routes │ ├── index.js │ └── users.js │ └── views │ ├── error.jade │ ├── index.jade │ └── layout.jade ├── README.md └── Vagrantfile /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | 3 | node_modules 4 | *.log 5 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v4.2 2 | -------------------------------------------------------------------------------- /Chapter_01/hello-world/app.js: -------------------------------------------------------------------------------- 1 | var express = require("express"); 2 | 3 | var app = express(); 4 | 5 | app.get("/", function(request, response) { 6 | response.send("Hello world!"); 7 | }); 8 | 9 | app.listen(3000, function() { 10 | console.log("Express app started on port 3000."); 11 | }); 12 | -------------------------------------------------------------------------------- /Chapter_01/hello-world/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "node app" 5 | }, 6 | "dependencies": { 7 | "express": "^5.0.0-alpha.2" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_02/mustache/mustache-test.js: -------------------------------------------------------------------------------- 1 | var Mustache = require("mustache"); 2 | var result = Mustache.render("Hi {{first}} {{last}}!", { 3 | first: "Nicolas", 4 | last: "Cage" 5 | }); 6 | 7 | console.log(result); -------------------------------------------------------------------------------- /Chapter_02/mustache/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "mustache": { 6 | "version": "2.3.0", 7 | "resolved": "https://registry.npmjs.org/mustache/-/mustache-2.3.0.tgz", 8 | "integrity": "sha1-QCj3d4sXcIpImTCm5SrDvKDaQdA=" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_02/mustache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "node app" 5 | }, 6 | "dependencies": { 7 | "mustache": "^2.3.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_02/random-integer/print-three-random-integers.js: -------------------------------------------------------------------------------- 1 | var randomInt = require("./random-integer"); 2 | console.log(randomInt()); 3 | console.log(randomInt()); 4 | console.log(randomInt()); 5 | -------------------------------------------------------------------------------- /Chapter_02/random-integer/random-integer.js: -------------------------------------------------------------------------------- 1 | var MAX = 100; 2 | 3 | function randomInteger() { 4 | return Math.floor((Math.random() * MAX)); 5 | } 6 | 7 | module.exports = randomInteger; 8 | -------------------------------------------------------------------------------- /Chapter_03/guestbook/app.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | var path = require("path"); 3 | var express = require("express"); 4 | var logger = require("morgan"); 5 | var bodyParser = require("body-parser"); 6 | 7 | var app = express(); 8 | 9 | var entries = []; 10 | app.locals.entries = entries; 11 | 12 | app.use(logger("dev")); 13 | 14 | app.set("views", path.resolve(__dirname, "views")); 15 | app.set("view engine", "ejs"); 16 | 17 | app.use(bodyParser.urlencoded({ extended: false })); 18 | 19 | app.get("/", function(req, res) { 20 | res.render("index"); 21 | }); 22 | 23 | app.get("/new-entry", function(req, res) { 24 | res.render("new-entry"); 25 | }); 26 | 27 | app.post("/new-entry", function(req, res) { 28 | if (!req.body.title || !req.body.body) { 29 | res.status(400).send("Entries must have a title and a body."); 30 | return; 31 | } 32 | entries.push({ 33 | title: req.body.title, 34 | body: req.body.body, 35 | published: new Date() 36 | }); 37 | res.redirect("/"); 38 | }); 39 | 40 | app.use(function(req, res) { 41 | res.status(404).render("404"); 42 | }); 43 | 44 | http.createServer(app).listen(3000, function() { 45 | console.log("Guestbook app started."); 46 | }); 47 | -------------------------------------------------------------------------------- /Chapter_03/guestbook/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-guestbook", 3 | "private": true, 4 | "scripts": { 5 | "start": "node app" 6 | }, 7 | "dependencies": { 8 | "body-parser": "^1.13.2", 9 | "ejs": "^2.3.3", 10 | "express": "^5.0.0-alpha.2", 11 | "morgan": "^1.6.1" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_03/guestbook/views/404.ejs: -------------------------------------------------------------------------------- 1 | <% include header %> 2 |