Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
'use strict';
var express = require('express'),
morgan = require('morgan'),
bodyParser = require('body-parser');
var tasksArray = ['Groceries', 'Take the dog out', 'Something else'];
// Create the express application object
var app = express();
app.set('view engine', 'pug');
app.set('views', './views');
/* istanbul ignore next */
if (process.env.NODE_ENV !== 'test') {
// Setup the loggin format, depending on running environment
app.use(morgan(process.env.NODE_ENV === 'development' ? 'dev' : 'combined'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(function (request, response, next) {
response.locals.year = 2020;
response.locals.season = 'Summer';
// Add the static middleware, pointed at the ./public directory
// app.use(express.static('public'));
//render index pg
app.get('/', function (request, response) {
//redirect to name pg'/', function (request, response) {
response.redirect('/' +;
//generate list from tasks array
app.get('/tasks', function (request, response) {
response.render('tasksTemplate', { tasksData: tasksArray });
//push user submitted task to task array'/tasks', function (request, response) {
response.render('tasksTemplate', { tasksData: tasksArray })
//body of name page
app.get('/tasks/:index', function (request, response) {
response.render('taskTemplate', { task: tasksArray[request.params.index] });
// allow other modules to use the server
module.exports = app;
extends ./layout
block bodyContents
h1 Tasks
form(action="tasks", method="POST")
input(type="text" name="task")
button(type="submit") submit
each task, index in tasksData
a(href="/tasks/" + index) #{task}
extends ./layout
block bodyContents
h1= task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment