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
Related Q & A:
- how to browserify a node-js module?Best solution by Stack Overflow
- How can I send a picture message to a phone from my email online?Best solution by Yahoo! Answers
- How can you send a picture to a friend?Best solution by Yahoo! Answers
- How can I send big music files from my computer to my friends by email?Best solution by Yahoo! Answers
- How can I send a file to a friend on Hotmail?Best solution by askdavetaylor.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.