简体   繁体   English

将GET与Node.js一起使用

[英]Using GET with Node.js

I want to use GET, to get the value of a variable, inside a node.js page I made, as I would normally do (with $_GET) using PHP. 我想在我制作的node.js页面中使用GET获取变量的值,就像我通常使用PHP(使用$ _GET)所做的那样。

Here is how it looks: 外观如下:

http://mygreatpage.herokuapp.com/myThing?X=57

The question is: 问题是:

How do I get the value of X (57 in the example above) inside my index.js file? 如何获取index.js文件中X的值(在上面的示例中为57)?

var app = require('express')();
var http = require('http').Server(app);
app.get('/myThing',function(req,res)
console.log(req.query.X);
    res.send(req.query.X);
}
      );
app.listen(3000);
console.log("server start");

在此处输入图片说明

check this for more detail 检查更多细节

check this for multiple param 检查此是否有多个参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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