WebFund 2016W Lecture 15: Difference between revisions
Created page with "==Video== The video from the lecture given on March 8, 2016 [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/lectures/comp2406-2016w-lec15-08Mar2016.mp4 is now availab..." |
|||
Line 6: | Line 6: | ||
==Code== | ==Code== | ||
===examforms-jquery/examforms-jquery.js=== | |||
<source lang="javascript" line> | |||
var http = require('http'); | |||
var express = require('express'); | |||
var bodyParser = require('body-parser'); | |||
var logger = require('morgan'); | |||
var port = 3000; | |||
var state = []; | |||
var app = express(); | |||
app.set('view engine', 'jade'); | |||
app.set('views', __dirname); | |||
app.use(logger('dev')); | |||
app.use(bodyParser.urlencoded({ extended: false })); | |||
app.use(express.static('.')); | |||
app.get('/', function(req, res, next) { | |||
res.render('index', { title: 'COMP 2406 Exam form demo' }); | |||
}); | |||
app.post('/add', function(req, res) { | |||
var obj = { name: req.body.name, | |||
city: req.body.city, | |||
country: req.body.country, | |||
birthday: req.body.birthday, | |||
email: req.body.email }; | |||
state.push(obj); | |||
res.redirect('/list'); | |||
}); | |||
app.get('/list', function(req, res) { | |||
// res.render('list', { title: 'People Listing', items: state, | |||
// pretty: true}); | |||
res.render('clientlist', { title: 'People Listing', pretty: true}); | |||
}); | |||
app.get('/items', function(req, res) { | |||
res.send(state); | |||
}); | |||
var serverUp = function() { | |||
console.log("ExamForms listening on port " + port); | |||
} | |||
var serverDown = function() { | |||
console.log("Server shutting down."); | |||
process.exit(0); | |||
} | |||
var server = http.createServer(app); | |||
server.listen(port); | |||
server.on('listening', serverUp); | |||
process.on('SIGINT', serverDown); | |||
</source> | |||
===examforms-jquery/clientlist.jade=== | |||
===examforms-jquery/showlist.js=== |
Revision as of 21:15, 8 March 2016
Video
The video from the lecture given on March 8, 2016 is now available.
Notes
Code
examforms-jquery/examforms-jquery.js
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var logger = require('morgan');
var port = 3000;
var state = [];
var app = express();
app.set('view engine', 'jade');
app.set('views', __dirname);
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static('.'));
app.get('/', function(req, res, next) {
res.render('index', { title: 'COMP 2406 Exam form demo' });
});
app.post('/add', function(req, res) {
var obj = { name: req.body.name,
city: req.body.city,
country: req.body.country,
birthday: req.body.birthday,
email: req.body.email };
state.push(obj);
res.redirect('/list');
});
app.get('/list', function(req, res) {
// res.render('list', { title: 'People Listing', items: state,
// pretty: true});
res.render('clientlist', { title: 'People Listing', pretty: true});
});
app.get('/items', function(req, res) {
res.send(state);
});
var serverUp = function() {
console.log("ExamForms listening on port " + port);
}
var serverDown = function() {
console.log("Server shutting down.");
process.exit(0);
}
var server = http.createServer(app);
server.listen(port);
server.on('listening', serverUp);
process.on('SIGINT', serverDown);