index.js
This file
Path
examples/markdown/index.js
45 lines · 978 bytes · JavaScript
Last changed by
Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
History of this fileTake it
The walk stopped after 200 commits: lines older than 34c83d7 point at it.
3.4.7Jonathan Ongbefore adoption34c83d7
lines 1–4why, one step back1/**2 * Module dependencies.3 */4Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
lines 5–7why, one step back5var express = require('../..');6var fs = require('fs');7var md = require('marked').parse;3.4.7Jonathan Ongbefore adoption34c83d7
lines 8–19why, one step back89var app = module.exports = express();1011// register .md as an engine in express view system1213app.engine('md', function(path, options, fn){14 fs.readFile(path, 'utf8', function(err, str){15 if (err) return fn(err);16 try {17 var html = md(str);18 html = html.replace(/\{([^}]+)\}/g, function(_, name){19 return options[name] || '';Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 20why, one step back20 });3.4.7Jonathan Ongbefore adoption34c83d7
lines 21–25why, one step back21 fn(null, html);22 } catch(err) {23 fn(err);24 }25 });Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 26why, one step back26});3.4.7Jonathan Ongbefore adoption34c83d7
lines 27–34why, one step back2728app.set('views', __dirname + '/views');2930// make it the default so we dont need .md31app.set('view engine', 'md');3233app.get('/', function(req, res){34 res.render('index', { title: 'Markdown Example' });Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 35why, one step back35});3.4.7Jonathan Ongbefore adoption34c83d7
lines 36–38why, one step back3637app.get('/fail', function(req, res){38 res.render('missing', { title: 'Markdown Example' });Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff
line 39why, one step back39});3.4.7Jonathan Ongbefore adoption34c83d7
line 40why, one step back40Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d
line 41why, one step back41/* istanbul ignore next */3.4.7Jonathan Ongbefore adoption34c83d7
lines 42–45why, one step back42if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45}