Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 34c83d7 point at it.

3.4.7Jonathan Ongbefore adoption34c83d7

lines 1–4why, one step back
1/**
2 * Module dependencies.3 */4

Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff

lines 5–7why, one step back
5var express = require('../..');
6var fs = require('fs');7var md = require('marked').parse;

3.4.7Jonathan Ongbefore adoption34c83d7

lines 8–19why, one step back
8
9var 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 back
20 });

3.4.7Jonathan Ongbefore adoption34c83d7

lines 21–25why, one step back
21 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 back
26});

3.4.7Jonathan Ongbefore adoption34c83d7

lines 27–34why, one step back
27
28app.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 back
35});

3.4.7Jonathan Ongbefore adoption34c83d7

lines 36–38why, one step back
36
37app.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 back
39});

3.4.7Jonathan Ongbefore adoption34c83d7

line 40why, one step back
40

Merge tag '3.9.0'Douglas Christopher Wilsonbefore adoptiondb4448d

line 41why, one step back
41/* istanbul ignore next */

3.4.7Jonathan Ongbefore adoption34c83d7

lines 42–45why, one step back
42if (!module.parent) {
43 app.listen(3000);44 console.log('Express started on port 3000');45}