Last active
January 24, 2019 15:10
-
-
Save LuisOsta/81ba7da0bc355d6060d21a7a33fd88e9 to your computer and use it in GitHub Desktop.
Basic index.js
This file contains 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 path = require("path"); | |
const hbs = require("hbs"); | |
const app = express(); | |
let PORT = 8080; | |
// servers any appropriate static files(i.e. css, js, etc) | |
const publicPath = path.join(__dirname, "../../public"); | |
app.use(express.static(publicPath)); | |
// setups hbs view path, where express will look for files | |
const partialPath = path.join(__dirname, "../views/partials"); | |
const viewPath = path.join(__dirname, "../views"); | |
// configures express to use hbs | |
hbs.registerPartials(partialPath); | |
app.set("view engine", "hbs"); | |
app.set("views", viewPath); | |
// base url for homepage | |
app.get("/", (req, res) => { | |
console.log("RENDERING THE HOME PAGE"); | |
res.render("home.hbs"); // express looks for a file in the views directory, | |
//then compiles and renders them to the client | |
}); | |
app.listen(PORT, () => { | |
console.log(`Server is up on port ${PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment