Skip to content

Instantly share code, notes, and snippets.

@teochengyong
Last active June 10, 2018 13:44
Show Gist options
  • Save teochengyong/32c41ed9b36d5c8a5cf28e63a82f4fc0 to your computer and use it in GitHub Desktop.
Save teochengyong/32c41ed9b36d5c8a5cf28e63a82f4fc0 to your computer and use it in GitHub Desktop.
Using express to serve Angular App
const express = require('express');
const compression = require('compression')
const path = require('path');
const app = express()
app.use(compression());
const port = process.env.PORT || 8080;
// static file serve
const dirName = 'dist'
app.use(express.static(path.resolve(`${dirName}`)))
// not found in static files, so default to index.html
app.use((req, res) => res.sendFile(path.resolve(`${dirName}/index.html`)))
app.listen(port, (e, b) => {
console.log(`Server has started in port ${port}`);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment