When I do a console.log on the variable event.body it shows article_url=http%3A%2F%2Fow.ly%2Fjo2n30fdI3y
How can I access the value of article_url
In other words, I want to access http%3A%2F%2Fow.ly%2Fjo2n30fdI3y
asked Sep 19, 2017 at 15:37
Kern Elliott
1,6595 gold badges42 silver badges68 bronze badges
-
Where is this coming from? Is it like a url query?Jonas Wilms– Jonas Wilms2017年09月19日 15:39:33 +00:00Commented Sep 19, 2017 at 15:39
-
What have you tried? Where is your code?Script47– Script472017年09月19日 15:39:45 +00:00Commented Sep 19, 2017 at 15:39
3 Answers 3
If you actually want to decode the percent encoded characters too, the best way is to use the native node.js querystring module:
const body = require( 'querystring' ).parse( event.body );
const article_url = body.article_url;
console.log( article_url );
answered Sep 19, 2017 at 15:41
Paul
142k28 gold badges285 silver badges272 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
console.log(event.body.split('=')[1])
answered Sep 19, 2017 at 15:38
lukaleli
3,6753 gold badges25 silver badges32 bronze badges
Comments
Simplest approach is probably the following:
var input = "article_url=http%3A%2F%2Fow.ly%2Fjo2n30fdI3y";
var output = input.split("=")[1];
console.log(output) // "http%3A%2F%2Fow.ly%2Fjo2n30fdI3y"
answered Sep 19, 2017 at 15:38
TimoStaudinger
42.7k16 gold badges91 silver badges96 bronze badges
Comments
lang-js