Node.js response API vs. Express.js response API

Tags: , , ,

Both, Node.js and Express.js have response API.
And it looks like there is even some overlapping between them, e.g.:

Which response API should be used for sending a response (e.g. JSON, files)? In other words, should I use response.write by Node.js or res.sendFile by Express.js?

P.S. Initially for some reason I assumed that Express.js is now a part of Node.js, which is not a right assumption, of course.


Bearing in mind that Express.js is now a part of Node.js

It isn’t.

what is the reason behind this overlapping?

Express.js uses the built-in HTTP module.

And which response API should be used?

The one for the response object you actually have, which will either be the built-in HTTP module or the Express.js module depending on if you are using Express.js or not.

Source: stackoverflow