Not able to render static index.html content from node

46 views
Skip to first unread message

rj

unread,
Mar 16, 2019, 7:45:55 PM3/16/19
to Angular and AngularJS discussion
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.

Reply all
Reply to author
Forward
0 new messages