Skip to content

Instantly share code, notes, and snippets.

@m-goos
Last active October 19, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-goos/32a35f61f112691a9f6048ff333cbbb9 to your computer and use it in GitHub Desktop.
Save m-goos/32a35f61f112691a9f6048ff333cbbb9 to your computer and use it in GitHub Desktop.
Express boilerplate
// 1. In the terminal: add express to the project: npm i express --save
// 2. In project root: create server.js and paste in this code
// 3. In package.json: change the 'start' script to "start": "node server.js",
// to test, run: ng build && npm start, then go to localhost:port
const express = require('express');
const app = express();
const port = (process.env.PORT || 8080);
// find the app name in package.json
app.use(express.static(__dirname + '/dist/<name-of-app>'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/<name-of-app>/index.html'));
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment