Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I URl encode something in Node.js?

I want to URL encode this:

SELECT name FROM user WHERE uid = me()  

Do I have to download a module for this? I already have the request module.

like image 707
TIMEX Avatar asked Jul 01 '11 23:07

TIMEX


People also ask

How do you encode in URL?

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

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.

Which function is used to encode a URL in Javascript?

JavaScript encodeURI() The encodeURI() method encodes a URI.


1 Answers

You can use JavaScript's encodeURIComponent:

encodeURIComponent('select * from table where i()') 

giving

'select%20*%20from%20table%20where%20i()' 
like image 130
Joe Avatar answered Oct 10 '22 09:10

Joe