How to add angular 4 to existing node.js application
I had the same case, I had a parse server on heroku and wanted to group it with Angular.
In my server.js file :
app.use(express.static(__dirname + '/dist'));
(You just need express)
I also use internationalization, so I made something quick (early stage, please don't judge) :
app.get('/', function(req, res) { let userLanguage = req.headers["accept-language"]; let langs = ['fr', 'en']; let preferred = userLanguage.substr(0, 2).toLowerCase(); console.log('User\'s preferred language is ' + preferred.toUpperCase()); if (langs.indexOf(preferred) >= 0) { res.redirect(preferred); } else { res.redirect('/en'); }});
My NG commands :
"postinstall": "npm run build-i18n","i18n": "ng xi18n --output-path src/i18n --out-file messages.xlf","build-i18n:fr": "ng build --output-path=dist/fr --aot --prod --bh /fr/ --i18n-file=src/i18n/messages.fr.xlf --i18n-format=xlf --locale=fr","build-i18n:en": "ng build --output-path=dist/en --aot --prod --bh /en/ --i18n-file=src/i18n/messages.en.xlf --i18n-format=xlf --locale=en","build-i18n": "npm run build-i18n:en && npm run build-i18n:fr"
My apps is built in 2 folders for the actual 2 languages, and the user is redirected to either of them when he comes to the app.