app.js
This file
Path
examples/markdown/app.js
44 lines · 944 bytes · JavaScript
Last changed by
Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
History of this fileTake it
The walk stopped after 200 commits: lines older than f98c112 point at it.
Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
lines 6–7why, one step back6var express = require('../../')7 , fs = require('fs')Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
lines 8–9why, one step back8 , md = require('node-markdown').Markdown;9Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
line 10why, one step back10var app = module.exports = express();Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
line 11why, one step back11Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
line 12why, one step back12// register .md as an engine in express view systemAdded app.render() local precedence testTj Holowaychukbefore adoptionf98c112
line 13why, one step back13Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
lines 14–27why, one step back14app.engine('md', function(path, options, fn){15 fs.readFile(path, 'utf8', function(err, str){16 if (err) return fn(err);17 try{18 var html = md(str);19 html = html.replace(/\{([^}]+)\}/g, function(_, name){20 return options[name];21 })22 fn(null,html)23 } catch(e){24 fn(e)25 }26 })27})Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
lines 28–33why, one step back2829// Optional since express defaults to CWD/views30app.set('views', __dirname + '/views');31app.set('view engine', 'md');3233app.get('/', function(req, res){Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
lines 34–35why, one step back34 res.render('index', { title: 'Markdown Example' });35})Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
line 36why, one step back36Updated markdown example with acceptance test.Robert Sköldbefore adoption4dbaaa2
lines 37–44why, one step back37app.get('/fail', function(req, res){38 res.render('missing', { title: 'Markdown Example' });39})4041if (!module.parent) {42 app.listen(3000);43 console.log('Express started on port 3000');44}