Send data from server to client. NodeJS, Express

440 Views Asked by At

I am trying to send data from my express server to the client side.

I have used app.post and app.get, the problem i'm having is that with either of those, the request must come from the client side. I need to send to push the data from the server side once a script has run has finished.

What i am doing is:

  • Client inputs data on client side
  • Data is send to the server using app.post api
  • Server runs script
  • Server sends data back to client side
2

There are 2 best solutions below

0
MTN On

For server to client communications, look into client-side libraries such as axios or ajax.

If you are suggesting something that for example: user inputs data to form, server responds with a new page, you may be seeking a template engine. In that case, look into the Express Docs for a template engine.

0
akira On

you probably looking for ejs engine. it allows you to send data from the server to the client. all you have to do is replace .html to .ejs for example: index.html will be index.ejs and you will have to add the engine in to your server as a middlware. just search about ejs