Just wanted to share my approach with you - I have an express server set up to communicate with a separate front-end angular server. By keeping them separate, I avoid adding redundant libraries to either one. When I'm ready, I simply set the build path for 'dist' to point to my server folder like this:
"apps": [
{
"root": "src",
"outDir": "server/dist", //<--- Here, I specify the location of my server.js, making it easy to build and prepare for production
"assets": [
"assets",
"favicon.ico"
],
Here is my complete server.js file that I run 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 serve 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 have the freedom to build my express backend as needed, communicate with it using routes, and still launch everything with a single node command.