Created
March 27, 2019 08:40
-
-
Save leslie-alldridge/75ab72ecacc1c1c2efe2a5a4d79feb1f to your computer and use it in GitHub Desktop.
server js for exercise
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 hbs = require("express-handlebars"); | |
var fs = require("fs"); | |
const server = express(); | |
// Middleware | |
server.engine( | |
"hbs", | |
hbs({ | |
defaultLayout: "main", | |
extname: "hbs" | |
}) | |
); | |
server.set("view engine", "hbs"); | |
server.use(express.static("public")); | |
server.use(express.urlencoded({ extended: false })); | |
server.get("/", function(req, res) { | |
fs.readFile("./invoice.json", "utf8", function(err, data) { | |
if (err) { | |
return res.status(500).send("An Error Occured!"); | |
} | |
var invoices = JSON.parse(data); | |
console.log(invoices); | |
res.render("puppies/index", invoices); | |
}); | |
}); | |
module.exports = server; |
invoice.json
{
"Invoices": [
{
"InvoiceID": "5ceffde5-6786-4987-b03a-bf88d262c286",
"StatusAttributeString": "OK"
},
{
"InvoiceID": "5ceffde5-6786-4987-b03a-bf88d262c286",
"StatusAttributeString": "OK"
},
{
"InvoiceID": "5ceffde5-6786-4987-b03a-bf88d262c286",
"StatusAttributeString": "WARNING",
"Warnings": [
{
"Message": "Only AUTHORISED invoices may have SentToContact updated."
}
]
},
{
"InvoiceID": "5ceffde5-6786-4987-b03a-bf88d262c286",
"StatusAttributeString": "ERROR",
"ValidationErrors": [
{
"Description": "Invoice not of valid type for creation"
}
]
}
]
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
index.hbs