The parameter values behind url cannot be obtained through express. Please give us some advice.

I want to get the value of the parameter articlePageId of the following url, but I have tried several ways to get it. I want to ask for help from my predecessors here. I hope I can take the time to give you some advice. Thank you!

https://localhost:8090/articlePage.html?articlePageId="+item.ID

console.log(fullUrl)      // http://localhost:8090/
console.log(req.path)     // /
console.log(req.params)   // {}
console.log(req.query.articlePageId)  // undefined
The

articlePageId.html, link reaches this page and sends the request to the background via vue-resource

window.onload = () => {
      const vm = new Vue({
        el: "-sharpapp",
        data: {
          dataGroup: [],
        },
        methods: {
          renderArticle() {
            this.$http.get("/", {

            }).then((res) => {
              this.dataGroup = res.data;
            }, (res) => {
              alert(res.status)
            })

          },
        },
        created() {
          this.renderArticle("/")

        }
      })
    }
The

background receives the get request, originally hoping to analyze the value of the url extracted articlePageId to retrieve the article from the database, but I don"t know why I can"t read the parameters after http://localhost:8090/

.
router.use("/articlePage",(req,res)=>{
  
    db.query(`SELECT * FROM articles_table WHERE ID="${pageId.id}"`,(err,page)=>{
      if(err){
        console.error(err);

        res.status(500).send("database error").end();
      }else{
        res.send(page);
      }
    })

  })

Ps: already uses body-parser on the primary server

Mar.04,2021

in express version 4.0
1, first check whether you have set body-parser middleware parsing request body

const bodyParser = require('body-parser');
app.use(bodyParser.json());  
app.use(bodyParser.urlencoded({ extended: false }));

if there is a setting and the fetch is still invalid, please move on to the second method.

2. I recommend using originalUrl for matching.

  const path = req.originalUrl;  // /articlePage.html?articlePageId=id
  const queryUrl = path.strsub(path.indexOf('?')+1); // articlePageId=id
  const lines = queryUrl.split('&');
  const val = {};
  for (const line of lines) {
    let [left, right] = line.split('=');
    right = decodeURIComponent(right);  // 
    val[left] = right;  // 
 }
//  articlePageId=1&limit=4
//     { articlePageId: 1, limit: 4 }

refer to the official document: http://expressjs.com/en/4x/ap.

or solve the problem directly with function

function getKeyValue(url) {
    let result = {};
    let reg = new RegExp('([\\?|&])(.+?)=([^&?]*)', 'ig');
    let arr = reg.exec(url);

    while (arr) {
        result[arr[2]] = arr[3];

        arr = reg.exec(url);
    }

    return result;
}

const path = req.originalUrl;
getKeyValue(path);


app.use (express.bodyParser ());

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30316-2bcea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30316-2bcea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?