Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the font different for res.end and res.send?

I have the following minimal basic express node js application:

var express = require ('express');
var app = express ();

app.get ('/', function (req, res) {
    res.send ('Hello');
});

app.listen (3000);

When I access this site on localhost:3000 I get a response that looks like:

res-send

If I change res.send ('Hello'); to res.end ('Hello');, the response is a different font like:

res-end

I am curious; why the difference?

like image 585
JuJoDi Avatar asked Apr 01 '14 00:04

JuJoDi


People also ask

What is difference between RES end and Res send?

res. send() is used to send the response to the client where res. end() is used to end the response you are sending.

What is the difference between RES JSON and Res send?

res. json forces the argument to JSON. res. send will take an non-json object or non-json array and send another type.

What is difference between Res send and RES status send in Express?

There is no actual difference between res. send and res.

What res end () does?

end() Function. The res. end() function is used to end the response process. This method actually comes from the Node core, specifically the response.


1 Answers

If you pass a string to res.send(), it automatically assumes a Content-Type of html.

res.end(), however, simply calls node's underlying end() implementation on the response stream, so no assumptions are made for the Content-Type.

The reason it renders differently is simply a browser decision to render a "pretty" default font for HTML, and a less-styled font for unknown content types.

like image 176
jmar777 Avatar answered Oct 22 '22 10:10

jmar777