Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js & Express.js Font Differentiation

I developed examples on Node.js and Express.js arbtrarily. After initiating example.js of each one shown below, I ran into a font differentiation between them. Even I know Express is a framework for Node, I couldn't find anywhere why typography change though.

Node.js:

const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Express.js:

var express = require('express')
var app = express()
app.get('/', function (req, res) {
  res.send('Hello World!')
})
app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

Output For Node.js:

Node's browser output

Output For Express.js:

Express's browser output

like image 809
Erhan Yaşar Avatar asked Jan 31 '17 08:01

Erhan Yaşar


People also ask

What is Nodejs used for?

It is used for server-side programming, and primarily deployed for non-blocking, event-driven servers, such as traditional web sites and back-end API services, but was originally designed with real-time, push-based architectures in mind.

Is node JS frontend or backend?

Node. js is sometimes misunderstood by developers as a backend framework that is exclusively used to construct servers. This is not the case; Node. js can be used on the frontend as well as the backend.

Is node js better than Python?

js vs Python, Node. js is faster due to JavaScript, whereas Python is very slow compared to compiled languages. Node. js is suitable for cross-platform applications, whereas Python is majorly used for web and desktop applications.

Is Nodejs a programming language?

Node. js is best defined as a JavaScript runtime that works on the famous and ultra-powerful V8 engine by JavaScript. In simpler terms, Node. js can be defined as a programming language that works well as a development runtime.


1 Answers

and here is Express.js version handles the same job

Well, no, not entirely. Your "plain Node" example explicitly sets the content-type to "text/plain", but you don't do the same for the Express example, in which case it will default to "text/html".

If the server tells the browser that the response contains HTML, the browser will apply a default CSS stylesheet, which usually includes a body font (something like Times New Roman).

When you use "text/plain", most browsers will render the content in a monospaced font.

like image 177
robertklep Avatar answered Oct 09 '22 21:10

robertklep