index.js
This file
Path
examples/view-constructor/index.js
46 lines · 1.1 KiB · JavaScript
Last changed by
lint: remove all unused varaiblesDouglas Christopher Wilsonbefore adoptione006622
History of this fileTake it
The walk stopped after 200 commits: lines older than dd2b897 point at it.
examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897
lines 1–46why, one step back1/**2 * Module dependencies.3 */45var express = require('../../');6var GithubView = require('./github-view');7var md = require('marked').parse;89var app = module.exports = express();1011// register .md as an engine in express view system12app.engine('md', function(str, options, fn){13 try {14 var html = md(str);15 html = html.replace(/\{([^}]+)\}/g, function(_, name){16 return options[name] || '';17 });18 fn(null, html);19 } catch(err) {20 fn(err);21 }22});2324// pointing to a particular github repo to load files from it25app.set('views', 'expressjs/express');2627// register a new view constructor28app.set('view', GithubView);2930app.get('/', function(req, res){31 // rendering a view relative to the repo.32 // app.locals, res.locals, and locals passed33 // work like they normally would34 res.render('examples/markdown/views/index.md', { title: 'Example' });35});3637app.get('/Readme.md', function(req, res){38 // rendering a view from https://github.com/expressjs/express/blob/master/Readme.md39 res.render('Readme.md');40});4142/* istanbul ignore next */43if (!module.parent) {44 app.listen(3000);45 console.log('Express started on port 3000');46}