Hi I am new to angular6
In development mode I have worked in angular 4200 port and node in different port (8080) in my operations.
but now I want to move my app into production mode.
for that I had build my angular project by using ng build
command. after i get a dist folder is created on the root folder.
so i went to server.js file here I had add my static file
app.use(express.static(path.join(__dirname,'dist/MDProject')));
app.use('/',(req,res)=>{
res.sendFile(path.join(__dirname,'dist/MDProject/index.html'))
});
click here to read my server.js file
by this when ever I redirect to my local host it is opening but in server.js side i didn't get any response.
when ever I try to login I am getting this error.
can anyone help me to solve this
I think there are 2 things wrong here in your code.
First, update your code
From:-
To:- This code needs to be added just before your
app.listen(app.get('port'))
codeSecond, Serve your file from your
public
folder(In your case I think it is thedist
folder). So update your code like this.Use this to go to index page.
with that you have to make folder in public in node
Then in your app dist folder -> index.html
This is my working code. Let me know if you have still any issue. :)
after I removed this line in my server.js file
and I paste this line before port creation.
now it is working fine.