nodejs: how to get original value from decoded url query string

if url contains non-english characters it's encoded in percent-decode format like this

%D8%A7%D9%84%D8%B3%D9%8A%D8%AF%20Ahmed

in nodejs program, I need to decode this value to its original value.

I've tried :

var qs = require('querystring');
console.log(qs.unescape('%D8%A7%D9%84%D8%B3%D9%8A%D8%AF%20Ahmed'));

and this

console.log(swapBytes(new Buffer(%D8%A7%D9%84%D8%B3%D9%8A%D8%AF%20Ahmed,'hex')).toString('utf8'));

and both give me wrong value : السيد Ahmed

the orginal value is : السيد Ahmed

This works for me:

var buf = new Buffer('d8a7d984d8b3d98ad8af2041686d6564', 'hex');
console.log(buf.toString('utf8'));

It displays the expected name on the right-hand side of the terminal. You might make sure that your LANG environment variable has .UTF-8 after the country/language (e.g. en_US.UTF-8). If you are using something like PuTTY for testing the output in the console, make sure you change the Remote character set option in Window->Translation for the connection to UTF-8 in the dropdown and click Apply.