Angular, image not found (GET 404) but it shows image after running ngbuild

Viewed 463

The problem is I have to run ngbuild each time after uploading image otherwise images can not be seen anymore

I have tried to store images somewhere on server other than /src/assets folder

server\images/image.jpg

Now images are stored but I can not see them in browser

static path

app.use(express.static(path.join(__dirname,'dist/my-app')));
1 Answers

Since you are using the static path as

app.use(express.static(path.join(__dirname,'dist/my-app')));

your image needs to be in dist/my-app/images folder instead of src/images to be able to access it without restarting the server.

You might need the logic to store the image in dist/my-app/images folder instead of src/images in production environment.

The reason why it is working after doing ng build is because it build the required file and copies all the images in the dist/my-app folder, so after doing ng build, new image is successfully copied in the dist folder, and thus it is available for your app.

Related