0

I have deployed my Angular project to heroku. It's showing error as not found. I tried running the same project in node server.js the same error some files not found. I tried this https://itnext.io/how-to-deploy-angular-application-to-heroku-1d56e09c5147 . But I think there's some error in the server.js file. Server.js

const express = require('express');
const app = express();
const path = require('path');
const port = process.env.PORT || 4200;
const server = require('http').Server(app);


// Serve only the static files form the angularapp directory
app.use(express.static(__dirname + '/RouterApp'));

app.get('/*', function(req,res) {

res.sendFile(path.join(__dirname+'/RouterApp/index.html'));
});

// Start the app by listening on the default Heroku port


server.listen(port, function () {
    console.log("App running on port " + port);
})

When I tried putting the path as /src/index.html, the index page is loading but not the Angular components. This is my directory structure

>>RouterApp
  >>...
  >>server.js
  >>src
    >>index.html
    >>components
  >>...

Error I'm getting while running using node server.js ENOENT: no such file or directory, stat '/data/data/com.termux/files/home/RouterApp/RouterApp/index.html'

When I try running the program on localhost:4200 it runs perfectly fine using ng serve. Here's the GitHub repo https://github.com/Pradeep2898/QuoraClone

MiaKhalifa
  • 23
  • 5

1 Answers1

0

Ok I get the issue. My project was not creating the dist folder on deployment. I tried this steps

cd RouterApp
ng build  //this will creat a dist folder
// now run the node server.js
node server.js
>>App running on port 4200
// Open the app locally on port 4200, https: localhost:4200
// It will work. Push the changes to git repository.
// It worked.

https://quora-ui-clone.herokuapp.com/

Try installing npm install http-server -g Then run http-server/dist

How to run the Dist Folder on Local Machine in Angular 6+?

MiaKhalifa
  • 23
  • 5