Skip to content

Instantly share code, notes, and snippets.

@fuzzylimes
Created May 16, 2018 10:48
Show Gist options
  • Save fuzzylimes/e1e34552808f9df0bf64640165450fb1 to your computer and use it in GitHub Desktop.
Save fuzzylimes/e1e34552808f9df0bf64640165450fb1 to your computer and use it in GitHub Desktop.
User thing
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}`);
});
{
"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"
}
}
<h1>Welcome</h1>
{{#if processed}}
<h2>Thanks for logging in.</h2>
<div>
<p>Here's your data:</p>
<p>{{data}}</p>
</div>
{{else}}
<h2>Please login</h2>
{{/if}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<title>NodeJWT</title>
</head>
<body>
<nav class="light-blue lighten-1" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo">User Tester</a>
<ul class="right hide-on-med-and-down">
<li>
<a href="#">Navbar Link</a>
</li>
</ul>
<ul id="nav-mobile" class="sidenav">
<li>
<a href="#">Navbar Link</a>
</li>
</ul>
<a href="#" data-target="nav-mobile" class="sidenav-trigger">
<i class="material-icons">menu</i>
</a>
</div>
</nav>
{{{body}}}
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment