I am using multer for file uploading. On the server I have this:
stream.on('finish', () => {
console.log('finished')
next()
})
What would be the best way (with what command) to notify the frontend that 'finished' has happened? I want to know this in order to have a loading bar.
Frontend and backend communicate with each other - via Http requests. The frontend will, for example, send entered data to the backend. The backend might then again validate that data (since frontend code can be tricked) and finally store it in some database.
Front-end developers work on what the user can see while back-end developers build the infrastructure that supports it. Front-end developers work on what the user can see while back-end developers build the infrastructure that supports it. Both are necessary components for a high-functioning application or website.
Front-end developer: Also called a front-end designer, they can create a site without any back-end development. The site they would create without a web developer, or using the backend, is a static site. A static site is something like a site for a restaurant or hair salon.
The front-end is the code that is executed on the client side. This code (typically HTML, CSS, and JavaScript) runs in the user's browser and creates the user interface.
That's what websockets are for. The server can send data to the client, and vice-versa. Check out socket.io.
Server : socket.emit("upload finished")
Client : socket.on("upload finished", function...)
While Jeremy Thille 's answer works well, beware of broadcasting event to all.
Socket.emit()
simply broadcasts message to all connected clients.
So you need to store the client id of the uploader and notify the progress only to that client and not all. Refer this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With