Home > Web Front-end > JS Tutorial > body text

How to use render and send in node.js

php中世界最好的语言
Release: 2018-05-30 09:46:16
Original
2128 people have browsed it

This time I will show you how to use render and send in node.js, and what are the precautions for using render and send in node.js. The following is a practical case. Let’s take a look.

If you want to write a quick test page, of course you can use res.send(). This

function will automatically help us set the Content-Type header and 200status code based on the content. send() can only be used once, the same as end. How is it different from end? Ability to automatically set MIME types.

If you want to use different status codes, you can:

res.status(404).send('Sorry, we cannot find that!');
Copy after login

If you want to use different Content-Types, you can:

res.set('Content-Type', 'text/html');
Copy after login

render:

var express = require("express");
var app = express();
app.set("view engine", "ejs");
app.get("/", function (req, res) {
 res.render("haha", {news:[]});
});
app.listen(3000);
Copy after login

send:

app.get("/check", function (req, res) { 
 res.set('Content-Type', 'text/html'); 
 res.send({ 
 "user" : "ok" 
 }); 
});
Copy after login
I believe I read this case You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

What are the commonly used mathematical functions in JS?

Detailed explanation of the use of common built-in functions in JS

The above is the detailed content of How to use render and send in node.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template