-1

I am trying to read multiple inputs from URL (may vary with every request) in NODEJS.

For eg: www.blahblah.com/api/abc/xyz/pop/god/ is requested,

I want to take 'abc','xyz','pop','god' and process each individually. the script i am passing it to, takes the input and passes it to a perl script to get the output.

I am using AngularJS and NodeJS.

any suggetions.

6
  • 1
    What have you tried so far and why didn't that work? Commented Sep 12, 2018 at 9:19
  • What do you mean by multiple inputs? Can you try to elaborate your question and the context of use? Do you mean to read req.params? Commented Sep 12, 2018 at 9:19
  • Please be more specific and a bit elaborate. If all you want to do is just use the parts of the URL, you might just use a substring method. Commented Sep 12, 2018 at 9:20
  • Possible duplicate of Using multiple parameters in URL in express Commented Sep 12, 2018 at 9:26
  • @Sreehari yes req.params. Commented Sep 12, 2018 at 10:12

1 Answer 1

0

I'll say. Make the ajax call with Json Data

$.ajax({
  type : "POST",
  url : "/yourServiceUrl",
  data :{
    data1 : data1Val,
    data2: data2Val,
    .
    .
    .
    datan: datanVal
  }
}).done((result)=>{});

Fetch the data in backed using

let data1 = req.body.data1;
let data2 = req.body.data2;
.
.
.
.
let datan = req.body.datan;

Regular expressions may also be used, and can be useful if you have very specific restraints, for example the following would match "GET /commits/71dbb9c" as well as "GET /commits/71dbb9c..4c084f9".

app.get(/^\/commits\/(\w+)(?:\.\.(\w+))?$/, function(req, res){
  var from = req.params[0];
  var to = req.params[1] || 'HEAD';
  res.send('commit range ' + from + '..' + to);
});

This should solve your problem :)

Sign up to request clarification or add additional context in comments.

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.