You can use JavaScript's encodeURIComponent:

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

giving

'select%20*%20from%20table%20where%20i()'
Answer from Joe on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURIComponent
encodeURIComponent() - JavaScript - MDN Web Docs
The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two surrogate characters).
Discussions

encodeURIComponent in nodejs 22 cuts $ sign instead of escaping
Version v22.15.1 Platform Linux localhost.localdomain 6.17.6-1-default #1 SMP PREEMPT_DYNAMIC Wed Oct 29 17:21:06 UTC 2025 (9e452b6) x86_64 x86_64 x86_64 GNU/Linux Subsystem No response What steps ... More on github.com
🌐 github.com
3
November 6, 2025
querystring result not consistent with encodeURIComponent
There was an error while loading. Please reload this page More on github.com
🌐 github.com
3
February 18, 2016
node.js - NodeJS decodeURIComponent not working properly - Stack Overflow
I'm just leaving this here, because I had the same problem. I was using the encodeURIcomponent(str) function in the client and in Nodejs when I did decodeURI(str) had the same problem. More on stackoverflow.com
🌐 stackoverflow.com
doc: decodeURIComponent and encodeURIComponent missing
📗 API Reference Docs Problem Version: ✍️ v10.19.0 Platform: ✍️ Linux strawberry 5.4.0-sabayon #1 SMP Fri May 8 19:23:19 UTC 2020 x86_64 Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz GenuineIntel GNU/Lin... More on github.com
🌐 github.com
8
June 8, 2020
🌐
W3Schools
w3schools.com › jsref › jsref_encodeuricomponent.asp
JavaScript encodeURIComponent() Method
The encodeURIComponent() method encodes special characters including: , / ?
🌐
Attacomsian
attacomsian.com › blog › nodejs-encode-decode-url
How to encode or decode a URL in Node.js
October 3, 2022 - const baseUrl = 'http://example.com/search?q=' const query = 'SELECT * from users WHERE id = 1' // Encode query string const encodedQuery = encodeURIComponent(query) // Build full URL const url = baseUrl + encodedQuery // Print full URL console.log(url) // http://example.com/search?q=SELECT * from users WHERE id = 1
🌐
SSOJet
ssojet.com › escaping › url-escaping-in-nodejs
URL Escaping in NodeJS | Escaping Techniques in Programming
A common pitfall with encodeURI() is its handling of characters like + or spaces within a query string parameter's value. These characters won't be escaped by encodeURI(). For encoding individual parameter values, encodeURIComponent() is the correct choice.
🌐
Bun
bun.com › modules › node:querystring › stringifyoptions › encodeuricomponent
property encodeURIComponent | Node.js querystring module | Bun
3 weeks ago - The function to use when converting URL-unsafe characters to percent-encoding in the query string.
🌐
Node.js
nodejs.org › api › querystring.html
Query string | Node.js v26.5.0 Documentation
encodeURIComponent <Function> The function to use when converting URL-unsafe characters to percent-encoding in the query string.
Find elsewhere
🌐
GitHub
github.com › node-modules › urlencode
GitHub - node-modules/urlencode: encodeURIComponent with charset · GitHub
encodeURIComponent with charset, e.g.: gbk · npm install urlencode ·
Starred by 143 users
Forked by 27 users
Languages   TypeScript 68.6% | JavaScript 31.4%
🌐
Dot Net Perls
dotnetperls.com › encodeuri-js
Node.js - encodeURI Use - Dot Net Perls
August 3, 2025 - Tip With encodeURIComponent, we convert valid URL characters to their encoded representation for use in a component (not a full URL).
🌐
LinkedIn
linkedin.com › pulse › encodeuricomponent-encodeuri-javascript-parathan-thiyagalingam-kr8sc
encodeURIComponent & encodeURI in JavaScript
October 29, 2023 - This is used to encode a single component of a URI, such as query parameters or fragments.It escapes all characters except the following: alphabetic characters, decimal digits, - _ . ! ~ * ' ( )It escapes characters that have special meanings ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURI
encodeURI() - JavaScript - MDN Web Docs
encodeURI, as the name implies, is used to encode a URL as a whole, assuming it is already well-formed. If you want to dynamically assemble string values into a URL, you probably want to use encodeURIComponent() on each dynamic segment instead, to avoid URL syntax characters in unwanted places.
🌐
npm
npmjs.com › search
encodeURIComponent - npm search
Npx command line for encodeURIComponent.
🌐
npm
npmjs.com › package › urlencode
urlencode - npm
October 28, 2023 - encodeURIComponent with charset. Latest version: 2.0.0, last published: 3 years ago. Start using urlencode in your project by running `npm i urlencode`. There are 627 other projects in the npm registry using urlencode.
      » npm install urlencode
    
Published   Oct 28, 2023
Version   2.0.0
🌐
GitHub
github.com › nodejs › node › issues › 5309
querystring result not consistent with encodeURIComponent · Issue #5309 · nodejs/node
February 18, 2016 - const x = { valueOf: function() { return 'other result'; }, toString: function() { return 'spec result'; } } encodeURIComponent(x) !== require('querystring').escape(x)
Author   nodejs
🌐
Uchicago
contest-server.cs.uchicago.edu › ref › JavaScript › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURIComponent.html
encodeURIComponent()
April 25, 2019 - The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed ...
🌐
GitHub
github.com › nodejs › node › issues › 33799
doc: decodeURIComponent and encodeURIComponent missing · Issue #33799 · nodejs/node
June 8, 2020 - https://nodejs.org/api/globals.html · Concise explanation of what you found to be problematic · ✍️ Recently I learned over a Pull Request, that the Node.js documentation lacks mentioning of decodeURIComponent() and encodeURIComponent(). According to browser-compat-data, the support was added in v0.1.100 and v0.1.100.
Author   nodejs
🌐
freeCodeCamp
freecodecamp.org › news › javascript-url-encode-example-how-to-use-encodeuricomponent-and-encodeuri
JavaScript URL Encode Example – How to Use encodeURIcomponent() and encodeURI()
August 4, 2020 - When accepting query parameters that may have reserved characters. ```JS let params = encodeURIComponent('mango & pineapple') let url = "http://mysite.com/?search=" + params; //http://mysite.com/?search=mango & pineapple