1

Hi I have a url of format

> http://127.0.0.1:3000/sss?AP=API&SE=AU

I used to follow the below code to query

var data=req.query[AP]

But now my url is

> http://127.0.0.1:3000/sss/API/AU

I am stuck as how to query this data.Any help regarding this will be much helpful.

2 Answers 2

3

try

var parse = require('connect').utils.parseUrl;
var pathname = parse(req).pathname;

var data = pathname.split('/');
// data[2] => API
// data[3] => AU

or

var parse = require('connect').utils.parseUrl;
var pathname = parse(req).pathname;

var data = pathname.match(/\/sss\/(\w+)\/(\w+)/)
if (data) {
  // data[1] => API
  // data[2] => AU
}
Sign up to request clarification or add additional context in comments.

Comments

2

What you could do is using the routing of express.

With something like this, you'll get your values directly in the req.params object:

var app   = require('express').express();

app.get( "/sss/:AP/:SE", function( req, res ) {
    console.log( req.params.AP, req.params.SE );
});

Best regards Robert

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.