Home:ALL Converter>Express server not deploying the angular 8 app

Express server not deploying the angular 8 app

Ask Time:2019-12-17T00:42:23         Author:Usama Hameed

Json Formatter

enter image description hereI am learning to build a simple mean stack application. I have default angular project which runs fine. I want to run the angular app through express server but it showing error "Cannot GET /" in the browser. Here is my code:

    const express = require("express");
const compression = require("compression");

const _port = 4100;
const _app_folder = 'src/dist/app';

const app = express();
app.use(compression());


// ---- SERVE STATIC FILES ---- //
app.get('*.*', express.static(_app_folder, {maxAge: '1y'}));

// ---- SERVE APLICATION PATHS ---- //
app.all('*', function (req, res) {
    res.status(200).sendFile('/', {root: _app_folder});
});

// ---- START UP THE NODE SERVER  ----
app.listen(_port, function () {
    console.log("Node Express server for " + app.name + " listening on http://localhost:" + _port);
});

Author:Usama Hameed,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59360850/express-server-not-deploying-the-angular-8-app
yy