app.get

编程入门 行业动态 更新时间:2024-10-08 06:23:25
本文介绍了app.get-res.send与return res.send之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是node和express的新手.我看过同时使用"res.send"和"return res.send"的app.get和app.post示例.这些都一样吗?

I am new to node and express. I have seen app.get and app.post examples using both "res.send" and "return res.send". Are these the same?

var express = require('express'); var app = express(); app.get('/', function(req, res) { res.type('text/plain'); res.send('i am a beautiful butterfly'); });

var express = require('express'); var app = express(); app.get('/', function(req, res) { res.type('text/plain'); return res.send('i am a beautiful butterfly'); });

推荐答案

return关键字从函数中返回,从而结束其执行.这意味着之后的任何代码行都不会被执行.

The return keyword returns from your function, thus ending its execution. This means that any lines of code after it will not be executed.

在某些情况下,您可能想使用res.send然后再做其他事情.

In some circumstances, you may want to use res.send and then do other stuff.

app.get('/', function(req, res) { res.send('i am a beautiful butterfly'); console.log("this gets executed"); }); app.get('/', function(req, res) { return res.send('i am a beautiful butterfly'); console.log("this does NOT get executed"); });

更多推荐

app.get

本文发布于:2023-11-25 06:24:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628663.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!