简体   繁体   中英

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

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

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

PS 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.

The original Node.js API for web servers is http , but the Express.js API was created with the objective to make the development process easier.

Express.js uses http API behind. So what kind of response to use? It will depend on your API choices, if you use Express.js or http .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM