How to send image to web server?

How can you send html and other files from a node.js server?

  • I am running (and learning) a basic node.js program that returns unformatted numeric data in the response object. The chrome browser just shows that data unformatted on screen. However, now I want to return HTML files, so I read an HTML file using the fs module and it returned that in the response object. The browser is showing the entire html instead of interpreting it. Here's what I want to do: Send an HTML file with a javascript code in it. Connect the javascript on the client with that in the server to excahange more HTML, css, javascript, json or other objects like image files etc. How can I establish this architecture? I am completely new to web development.

  • Answer:

    You need to read about how http works. It sends the header to browser in response. Check the structure of http request and response headers. In short to answer your question, you need to set content type of response object as text/html. response.setHeader("Content-Type", "text/html");

Sushant Gawali at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.