Just want to jump in and tell you I have an express server that talks to front-end angular server, I build them separate so I dont fill one or the other with redundant libraries and then once im ready I just have the build path for 'dist' point to my server folder like so:
"apps": [
{
"root": "src",
"outDir": "server/dist", //<--- Here, I point to where my server.js, so i can simply build and its ready for production
"assets": [
"assets",
"favicon.ico"
],
This is my whole server.js that I launch with node server.js
let express = require('express');
let passport = require('passport');
let session = require('express-session');
const config = require('./server/auth/config');
let oauth2orize = require('oauth2orize');
const app = express();
const cors = require('cors');
const html = __dirname + '/dist';
app.use(passport.initialize());
app.use(passport.session());
app.use(cors());
app.options('*', cors());
app.use('/api', require('./server/misc/routemanager'));
/**
* This line tells the server to provide our angular site (after running ng build with it)
*/
app.use(express.static(html));
app.get('*', function(req, res) {
res.sendFile(html + '/index.html')
});
app.listen(4949, () => {
console.log(`Node Express server listening on http://localhost:4949`);
});
Now I can build my express backend however I want and talk to it through routes, and still launch the whole thing in one node launch