How to do it...

This section covers how to implement static file serving in Express.

  1. First, let's build our Angular application by running the Angular-CLI build command in our project directory:
ng build
  1. Next, let's create a new /routes/angular.js route in our Express project, to configure serving our Angular application. We will need to define a relative route from this project to our Angular project using Node.js's core path module:
var path = require('path');var express = require('express');var router = express.Router();var angularBuildPath = path.resolve(__dirname,     '../../my-angular-project/dist');router.use(express.static(angularBuildPath));router.get('*', (req, res, next) => { if (req.url.startsWith('/api')) return next(); res.sendFile(path.join(angularBuildPath, ...

Get MEAN Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.