Last active
October 19, 2020 16:39
-
-
Save m-goos/32a35f61f112691a9f6048ff333cbbb9 to your computer and use it in GitHub Desktop.
Express boilerplate
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
// 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