I wanted to render the static files of Angular from node my node server. 

As an experiment, Below are the steps i took:

1. Created a dist folder by building my Angular project using 
ng build --prod

2. Copied the `dist` folder to the root directory of my node server

3. Configured express app to point to index.html within the `dist` folder 
where the node server shoots up. Below are the snips of configuration code 
i wrote -
app.use(express.static(path.join(__dirname, '../front-end/dist/'))) 

app.get('*', (req, res) => {
 return res.sendFile(path.join(__dirname, 
'../front-end/dist/my-first-app/index.html'))
})

4. When i run my node server locally on port 3000 If i am correct, it 
should get redirected to index.html page within the angular `dist` folder. 
Well, i see the redirection attempt being made by node. However, after 
redirection the browser is failing to load the html within the index.html 
file. It throws the below error on the console-

Uncaught SyntaxError: Unexpected token <
The above error tells clearly that the browser failed to load the html 
page. I believe my understanding is correct. But i am not able to figure 
out why. I hope i get some answers here.

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to