Skip to content

Instantly share code, notes, and snippets.

@medeirosjoaquim
Created March 5, 2019 19:55
Show Gist options
  • Save medeirosjoaquim/c3e8376a62b2273db164ed92d636a1f1 to your computer and use it in GitHub Desktop.
Save medeirosjoaquim/c3e8376a62b2273db164ed92d636a1f1 to your computer and use it in GitHub Desktop.
simple ExpressJS spa
const express = require('express')
const bodyParser = require('body-parser')
const path = require('path')
const app = express()
// assets. Static JS, CSS, fonts
app.use('/public', express.static(path.join(__dirname, '../public')))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
// SPA default configuration
// it is important to declare this after the assets rule
app.get('*', (req, res, next) => {
res.sendFile('path to your html file')
})
// start server
const server = app.listen(process.env.PORT || 3000, () => {
console.log(`server running on port ${server.address().port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment