index.js
This file
Path
examples/markdown/index.js
45 lines · 978 bytes · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 1–45why, one step back1/**2 * Module dependencies.3 */45var express = require('../..');6var fs = require('fs');7var md = require('marked').parse;89var 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] || '';20 });21 fn(null, html);22 } catch(err) {23 fn(err);24 }25 });26});2728app.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' });35});3637app.get('/fail', function(req, res){38 res.render('missing', { title: 'Markdown Example' });39});4041/* istanbul ignore next */42if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45}