res.status() 与 res.status 代码
res.status() vs. res.statusCode
我想知道这两种不同的方法在expressjs中是否相同?
res.statusCode = 500;
return res.json({
status: "error"
});
或
return res.status(500).json({
status: "error"
});
the res
object is an enhanced version of Node’s own response object and supports all built-in fields and methods.
Sets the HTTP status for the response. It is a chainable alias of Node’s response.statusCode.
所以结果是一样的。 expressjs 刚刚添加了 statusCode
.
的链式版本
同一个代码中有多个状态代码,例如状态代码 200、404 和 500? 200为成功,404为没有数据匹配。
我想知道这两种不同的方法在expressjs中是否相同?
res.statusCode = 500;
return res.json({
status: "error"
});
或
return res.status(500).json({
status: "error"
});
the
res
object is an enhanced version of Node’s own response object and supports all built-in fields and methods.
Sets the HTTP status for the response. It is a chainable alias of Node’s response.statusCode.
所以结果是一样的。 expressjs 刚刚添加了 statusCode
.
同一个代码中有多个状态代码,例如状态代码 200、404 和 500? 200为成功,404为没有数据匹配。