• nunjucks, html markup • jQuery (javascript client side) • sass, what we are using to write CSS • grunt gulp, task runner • gov_uk modules (toolkit, elements, template) • git, version control
next) { // on request type if (request.method === 'POST') { // log out request request method and url console.log(` ==> ${request.method} request on ${request.url} `.green) // log out body console.log(request.body) console.log(` ^ params are above `.green) } else { // log out request request method and url console.log(` ==> ${request.method} request on ${request.url} `.yellow) } // send to next function next() })
(request, response) { response.render('index') }) • get, the type of request (also post, put, del, or magic all) • request - information that is sent from the browser • response - what we will be sending back to the browser • response.render - what we are going to do, in this case render will display a page (also send, redirect)
the url i.e /cats and passes it to a view router.get('/:type', function (request, response) { response.render('index', {id: request.params.type}) }) // takes a var from a form post and passes it to a view router.post('/', function (request, response) { response.render('index', {id: request.body.type}) }) // takes a var from a pre-populated session and passes it to a view router.get('/', function (request, response) { response.render('index', {id: request.session.type}) })
const router = express.Router() router.get('/', function (request, response) { response.render('index') }) module.exports = router We can now re use these small routes // now we can use these in routes routes.js to re-use the routes const generalRoutes = require(path.resolve('app/routes/general/sprint1.js')); app.use('/sprint1', generalRoutes); app.use('/sprint2', generalRoutes);
needs a form with a post router.get('/details', function (request, response) { response.render('page') }) // now we need to do a post, save and maybe a redirect router.post('/details', function (request, response) { request.session.details = request.body; response.redirect('/display') }) // now we can get the session back on the get and display it on the page router.get('/display', function (request, response) { const formData = request.session.details response.render('page', {data: formData}) })
and can be scroped by prefixing the field i.e bank <input type="text" id="first-name" name="bank[accountNumber]" class="form-control" value="{{ data.bank.accountNumber }}" />