Last active
July 13, 2020 18:30
-
-
Save usmanity/da0127f13538f16b95bcc770c9f781f7 to your computer and use it in GitHub Desktop.
Use the following for being able to safely get body content from HTTP requests, set the view engine (change to your liking), and displaying static content
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
// create an express app (import express first) | |
const app = express(); | |
// tell app to use bodyParser, I believe this still needs to be imported but it's installed with express last I checked | |
// bodyParser will help keep your incoming http POST body clean | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: false})); | |
// set the view engine to be pug ONLY if you want a view engine | |
// if you're displaying static content in vue.js or React, you can just let it be HTML | |
// change pug to others like `jade`, `htmling`, etc. | |
app.set('view engine', 'pug'); | |
app.set('views', './public'); | |
// this will allow you to serve any static files | |
// I've separated my css and js but feel free to structures yours however you like | |
app.use("/styles", express.static(__dirname + '/styles')); | |
app.use("/js", express.static(__dirname + '/js')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment