【发布时间】:2014-12-05 04:49:30
【问题描述】:
如何检查传递给 Express.js 应用程序的查询字符串是否包含任何值?如果我的 API URL 可能是:http://example.com/api/objects 或 http://example.com/api/objects?name=itemName,那么哪些条件语句可以确定我要处理的内容?
我当前的代码如下,它总是评估为“应该没有字符串”选项。
if (req.query !== {}) {
console.log('should have no query string');
}
else {
console.log('should have query string');
}
【问题讨论】:
-
不确定
node是否支持这个,但也许你可以使用this answer来检查req.query的长度是否大于0。 -
你用的是快递吗?
标签: javascript node.js express