-1
I am to send a simple project that is working perfectly on my local computer, and I need to send it to the Heroku server, for this it is necessary to configure a file that will simulate Node Express in Angular, and necessary also the building of the project that I realized with the command ng build --prod
.
When executing the command you created a folder called dist at the root of the project, and then set up the server.js file as you can see below;
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/dist/index.html');
});
app.listen(4200);
After configuring it was necessary to execute the command node server.js
to upload the application using the Node server.
To verify that everything was right I typed the URL http://localhost:4200/
and returned me the following error message below;
C: Blog API api blog>Node server.js Error: ENOENT: no such file or directory, stat 'C: Blog API blog. index.html'
This message indicates that the Node server is not finding the main project file which is the index.html
, but I don’t understand why this is happening and I need help.
To move up an angular application run the ng build -Prod command and then move all the contents of the dist folder up to your server. You don’t need the Ode.
– Eduardo Vargas
@Eduardovargas all right, but I need to know why I can’t upload the application using the settings I made in the file
server.js
– wladyband
@Eduardovargas if I send the Heroku project to be configured the
dist
, it will end up sending to the Heroku project more than 20 megas of files and will set up to send only thedist
will get lighter the project because I will only send 5 to 2 megas of file.– wladyband
Not only send the content of dist and it should work
– Eduardo Vargas
I tried not to work. gave this error message
! [remote rejected] master -> master (pre-receive hook declined)
is why I need to know what’s wrong with server.js file configuration– wladyband