Recently, there is a functional requirement to monitor local file changes, and based on this, relevant information must be displayed on the front end in real time.
The first thing I thought of was to put the monitoring logic on the front end, and call the back-end interface every time a new file appears.
I also went to the Internet to find a lot of blogs about how js monitors file change events, and found that it can be implemented with fs or chokidar, so I think they can also be used in vue. An error was reported when it was actually used.
Later, I asked my front-end colleague, and she was surprised that I wrote node code in Vue. . . And pointed out that I actually want the front end to do the work of the back end. . .
I fell into deep thought for a moment, and I really didn't want to understand. In my subconscious, nodejs is approximately equal to js, and js can be written in vue, and of course nodejs can also be written. For the distinction between nodejs and js, I don’t understand it.
In fact, the only commonality between nodejs and js may be that they are both based on the syntax of ECMAScript. One is browser-based javascript (front-end JS); the other is server-based javascript (back-end Node.js)
That is to say, front-end js development and nodejs development, except that js is overlapped, other skills have nothing to do with each other.
Later, I rethought it, and the monitoring of file changes has to be done on the back end. For real-time front-end display, simply, you can let the front-end poll; more formally, use websocket.