Skip to content

Instantly share code, notes, and snippets.

Last active Aug 26, 2017
What would you like to do?
htmlController for second express example
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var jsonParser = bodyParser.json();
module.exports = function(app) {
// This contains all of the endpoints that return views/html.
// The function takes an app object and adds the endpoints
// to the app.
app.get('/', function(req, res) {
res.send('<html><head><link href=assets/style.css type=text/css rel=stylesheet /></head><body><h1>Donuts</h1></body></html>');
app.get('/form', function(req, res){
res.sendFile(__dirname + '/form.htm');
app.get('/person/:id', function(req, res) {
res.send('<html><head></head><body><h1>Donuts for Person ' + + '</h1></body></html>');
});'/person', urlencodedParser, function(req, res){
res.send('Thank you!');
});'/personjson', jsonParser, function(req, res){
res.send('Thankyou for the json data');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment