Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Express encodes the URL - how to decode

People also ask

How do I decode and encode in node JS?

Using Clean architecture for Node.The buffer object can be encoded and decoded into Base64 string. The buffer class can be used to encode a string into a series of bytes. The Buffer. from() method takes a string as an input and converts it into Base64.

How do you decode or encode a URL in Javascript?

Decoding in Javascript can be achieved using decodeURI function. It takes encodeURIComponent(url) string so it can decode these characters. 2. unescape() function: This function takes a string as a single parameter and uses it to decode that string encoded by the escape() function.

What is URL encoded in node JS?

urlencoded() is a built-in middleware in Express. js. The main objective of this method is to parse the incoming request with urlencoded payloads and is based upon the body-parser. This method returns the middleware that parses all the urlencoded bodies.


Update 16/03/18

escape and unescape are deprecated.

Use:
encodeURIComponent('אובמה') // %D7%90%D7%95%D7%91%D7%9E%D7%94
decodeURIComponent('%D7%90%D7%95%D7%91%D7%9E%D7%94') // אובמה

Old answer

unescape('%u05D0%u05D5%u05D1%u05DE%u05D4') gives "אובמה"

Try:

var querystring = unescape(query);


You should use decodeURI() and encodeURI() to encode/decode a URL with foreign characters.

Usage:

var query = 'http://google.com';
query = encodeURI(query);
query = decodeURI(query); // http://google.com

Reference on MDN:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI