eatorres
eatorres

Reputation: 179

Express static file is not updating

I'm running a local server with express. The server is able to display some local files from my computer. Amongst them there is a file called "lastResult.txt" which gets updated every time I run a bash script.

For some reason, when I run the server and try to display the file, it shows a version from a week ago. This file file has been updated locally more recently than a week ago. This persists even after restarting the server or even on different browsers.

I am using the serve-index module to display directories.

Upvotes: 3

Views: 2799

Answers (2)

MER
MER

Reputation: 1551

This question has already been answered.
I'm adding to it in case someone needs an example of a problem like this, (that is non-obvious).

Had a similar problem while using EJS and express.

  • I was importing a header.
  • The header loaded the CSS.
  • There was a CSS file named base.css in two different folders (same CSS file name two different folders projectroot/pages/base.css && projectroot/views/base.css )
  • The folder the header.ejs file was in was projectroot/views/ (this is the base.css I wanted)
  • From a path perspective to intentionally load the other css file should have required: ../pages/base.css
  • To be completely explicit I should have references the CSS file in the local directory like this: ./base.css but instead I referenced it like base.css
  • Surprisingly ... the CSS file that was being loaded was the one in the projectroot/pages/ directory not the projectroot/views/ directory
  • Changing the reference to ./base.css fixed the problem

Upvotes: 0

rsp
rsp

Reputation: 111336

You didn't say how do you serve the static files - with express.static or with some custom handlers. The express.static doesn't cache the files but your custom handlers might. In any case, those files can be cached on the client depending on the value of ETag and Max-Age but even then they should not persist after accessing with another browser.

From what you're describing it seems that you are not updating the correct files, or in the correct directory. Of course it's impossible to be sure since you didn't include even a single line of your code so one can only speculate but it seems to be the case.

Upvotes: 4

Related Questions