Created
May 16, 2018 10:48
-
-
Save fuzzylimes/e1e34552808f9df0bf64640165450fb1 to your computer and use it in GitHub Desktop.
User thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const exphbs = require('express-handlebars') | |
const app = express(); | |
// Handlebars Middleware | |
app.engine('handlebars', exphbs({defaultLayout: 'main'})); | |
app.set('view engine', 'handlebars'); | |
function homePage(req, res) { | |
if (req.dataProcessed) { | |
console.log(req.dataProcessed); | |
// res.send(req.dataProcessed) | |
res.render('index', {processed: true, data: req.dataProcessed}); | |
} else { | |
console.log('No data found'); | |
// res.send('Not Found'); | |
res.render('index', {processed: false}) | |
} | |
} | |
function testing(req, res, next) { | |
req.dataProcessed = 'I made this'; | |
return next() | |
} | |
// Index Route | |
app.get('/', homePage); | |
app.post('/test', testing, homePage); | |
const port = 5000; | |
app.listen(port, () => { | |
console.log(`Server started on port: ${port}`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "nodels", | |
"version": "1.0.0", | |
"description": "Simple program to play with local storage", | |
"main": "app.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "fuzzylimes", | |
"license": "MIT", | |
"dependencies": { | |
"express": "^4.16.3", | |
"express-handlebars": "^3.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment