Skip to content

Instantly share code, notes, and snippets.

@natmegs
Last active August 26, 2017 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natmegs/43b44d0735d0d05686cc9dd3638cd18f to your computer and use it in GitHub Desktop.
Save natmegs/43b44d0735d0d05686cc9dd3638cd18f to your computer and use it in GitHub Desktop.
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 ' + req.params.id + '</h1></body></html>');
});
app.post('/person', urlencodedParser, function(req, res){
res.send('Thank you!');
console.log(req.body.firstname);
console.log(req.body.lastname);
});
app.post('/personjson', jsonParser, function(req, res){
res.send('Thankyou for the json data');
console.log(req.body.firstname);
console.log(req.body.lastname);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment